Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: output file missing first FQDN URL for first sub tree value #1

Open
sambacha opened this issue Aug 20, 2023 · 1 comment
Open

Comments

@sambacha
Copy link
Owner

Missing URL for first entry

example:

cat subtree_commands_20230820-102241-f051091.txt
git subtree add --prefix=lib/forge-std  74cfb77e308dd188d2f58864aaf44963ae6b88b1
git subtree add --prefix=lib/solmate https://github.com/foundry-rs/forge-std bfc9c25865a274a7827fea5abf6e4fb64fc64e6c
git subtree add --prefix=lib/pigeon https://github.com/transmissions11/solmate ac4824da1fbeeaed88ab1b349f7b02c1624bc723
git subtree add --prefix=lib/safe-tools https://github.com/manifoldfinance/pigeon ce6c654a76d91b619ab7778c77d1a76b3ced6666
git subtree add --prefix=lib/openzeppelin-contracts https://github.com/0xKitsune/safe-tools 121be5dd09caa2f7ce731f0806b0e14761023bd6
git subtree add --prefix=lib/properties https://github.com/OpenZeppelin/openzeppelin-contracts bb1b78542b3f38e4ae56cf87389cd3ea94387f48
@sambacha
Copy link
Owner Author

using:

#!/usr/bin/env bash

set -eo pipefail

# Since bash 5.0, checkwinsize is enabled by default which does
# update the COLUMNS variable every time a non-builtin command
# completes, even for non-interactive shells.
# Disable that since we are aiming for repeatability.
test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null

export LC_ALL=C

# Limits recursive function
# @see BASH(1)
[[ -z "$FUNCNEST" ]] && export FUNCNEST=100

# simplifies both the tag name used when making a release
# and the computed version number take the date/time from the current
# commit, and then append the hash.  That way the version number always
# corresponds to a commit.
VERSION_ID=${VERSION_ID:-$(git show -s "--format=%cd-%h" "--date=format:%Y%m%d-%H%M%S")}

# @stdout Output filename
output_file="subtree_commands_$VERSION_ID.txt"

# Temporary file for submodule status
temp_file="temp_status_$(date +%s).txt"

# Check if .gitmodules exists
if [[ ! -f .gitmodules ]]; then
  echo "⛔️ Error: .gitmodules file not found."
  exit 1
fi

# Create or empty the output file
# use `:` to intentionally check that it's readable
: >"$output_file"

# Extract the submodule information
while IFS= read -r line; do
  if [[ "$line" == *'url = '* ]]; then
    # Extract the URL
    url=$(echo "$line" | cut -d'=' -f 2 | xargs)
  elif [[ "$line" == *'path = '* ]]; then
    # Extract the path
    path=$(echo "$line" | cut -d'=' -f 2 | xargs)

    # Get the hash for the submodule
    git submodule status --cached "$path" >"$temp_file"
    hash=$(cat "$temp_file" | awk '{print $1}' | sed 's/-//')

    # Append the git subtree command to the output file
    echo "git subtree add --prefix=$path $url $hash" >>"$output_file"
  fi
done <.gitmodules

# Clean up temp file
rm "$temp_file"

# Check the output file for any lines that don't start with 'git subtree'
if grep -qv '^git subtree' "$output_file"; then
  # Remove those lines
  sed -i '/^git subtree/!d' "$output_file"
  echo "ℹ️ Notice: Lines not starting with 'git subtree' found and removed."
fi

echo "✅ Commands written to $output_file."
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant