Skip to content

Instantly share code, notes, and snippets.

@2bbb
Forked from tyhenry/list-of-addons-git.sh
Created December 4, 2020 06:51
Show Gist options
  • Save 2bbb/ac46268f62fee0e08be8eab389729dc6 to your computer and use it in GitHub Desktop.
Save 2bbb/ac46268f62fee0e08be8eab389729dc6 to your computer and use it in GitHub Desktop.
list ofxAddons for OF project, with git repo / version info > 'addons.git.make'
#!/bin/bash
# list-of-addons-git.sh
#
# to be run inside of an openFrameworks project with 'addons.make' file.
# writes 'addons.git.make' - list addons and git repo urls, branches, and commits to 'addons.git.make' file
INPUT="addons.make" # addons list file
OUTPUT="addons.git.make" # output file
if [ -f "$INPUT" ]; then
> $OUTPUT # create/clear output file
else
echo "[Error] No $INPUT file found in directory: $PWD"
exit 1
fi
# for each addon in addons.make
while read -r ADDON; do
# temp move to addon dir
pushd "../../../addons/$ADDON" >/dev/null
LINEOUT=""
# if git repo...
if git rev-parse --git-dir > /dev/null 2>&1; then
:
# read branch info
info=$( git branch -vv | grep -m 1 "^*" | tr -s ' ') # '* branch-name commit-hash [remote-name/remote-branch] msg'
# local
BRANCH=$( echo "$info" | cut -d ' ' -f 2 ) # 'branch-name'
COMMIT=$( echo "$info" | cut -d ' ' -f 3 ) # 'commit-hash' (HEAD)
# remote
remote=$( echo "$info" | cut -d ' ' -f 4 ) # '[remote-name/remote-branch]'
REMOTE_BRANCH=$BRANCH
REMOTE_URL=""
if [[ "$remote" =~ ^\[.*\/.*\] ]]; then
remote=$( echo "$remote" | sed 's/[][]//g' ) # 'remote-name/remote-branch'
REMOTE_NAME=$( echo "$remote" | cut -d '/' -f 1) # 'remote-name'
REMOTE_BRANCH=$( echo "$remote" | cut -d '/' -f 2) # 'remote-branch'
REMOTE_URL=$( git remote get-url "$REMOTE_NAME" )
else
echo "[Warning] $ADDON repo - branch [$BRANCH] is not tracking a remote git repo!"
fi
# output 'ofxAddon https://github.com/foo/bar.git master c0mm1t'
LINEOUT=$( echo "$ADDON $REMOTE_URL $REMOTE_BRANCH $COMMIT" )
# debug
# printf " info: $info \n BRANCH: $BRANCH \n COMMIT: $COMMIT \n remote: $remote \n REMOTE_NAME: $REMOTE_NAME \n REMOTE_BRANCH: $REMOTE_BRANCH \n REMOTE_URL: $REMOTE_URL\n\n"
else
: # this is not a git repository
LINEOUT=$( echo "$ADDON" )
fi
#)
popd >/dev/null
echo "$LINEOUT" | tee -a "$OUTPUT" # console log & append to file addons.git.make
done < $INPUT
echo "[Notice] Finished writing file $OUTPUT"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment