diff options
Diffstat (limited to 'git-config-save')
-rwxr-xr-x | git-config-save | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/git-config-save b/git-config-save index 9e742d1..5c040e4 100755 --- a/git-config-save +++ b/git-config-save @@ -26,27 +26,31 @@ # # Storage format: # -# - Use ~/.config/gitconfigs/ as base -# - Repository identifier is determined by the first commit ID +# - Use ~/.config/gitconfigs/ as base. +# - Repository identifier is determined by it's path in the system. +# That's the best choice if you have the same repository checked out +# multiple times and with different configurations. +# - Repository identifier can also be determined by the first commit ID # (not repo URL or any other volatile information). So this # script may fail if you're doing improbable stuff like rebasing # your repo and removing the initial commit. # # How it saves an item: # -# - Find all git configurations -# - Make a backup at $BASE/$ID/config.$DATE if config differs -# - Save the config at $BASE/ID +# - Find all git configurations. +# - Make a backup at $BASE/$ID/config.$DATE if config differs. +# - Save the config at $BASE/ID. # # How it restore an item: # -# - Copy each config from $BASE/ID, if available and if it differs -# - Restore always save a timestamped copy at .git/config.$DATE +# - Copy each config from $BASE/ID, if available and if it differs. +# - Restore always save a timestamped copy at .git/config.$DATE. # Parameters BASENAME="`basename $0`" BASE="$HOME/.config/gitconfigs" DATE="`date +%Y%m%d%I%M%S`" +FILENAME="gitconfig.saved" # Ensure we have a base and that is minimally safe mkdir -p $BASE @@ -62,22 +66,23 @@ function git_config_save { # Repository ID # https://stackoverflow.com/questions/34874343/how-can-i-uniquely-identify-a-git-repository - ID="`git rev-list --parents HEAD | tail -1`" + #ID="`git rev-list --parents HEAD | tail -1`" + ID="$PWD" # Display ID - echo $ID + #echo $ID # Create config folder mkdir -p $BASE/$ID # Make a backup - if [ -f "$BASE/$ID/config" ] && ! diff .git/config $BASE/$ID/config &> /dev/null; then + if [ -f "$BASE/$ID/$FILENAME" ] && ! diff .git/config $BASE/$ID/$FILENAME &> /dev/null; then echo "Differences detected at `pwd`, making a backup..." - cp $BASE/$ID/config $BASE/$ID/config.$DATE + cp $BASE/$ID/$FILENAME $BASE/$ID/$FILENAME.$DATE fi # Save - cp .git/config $BASE/$ID/config + cp .git/config $BASE/$ID/$FILENAME } # Restore config tor a repository @@ -90,22 +95,23 @@ function git_config_restore { # Repository ID # https://stackoverflow.com/questions/34874343/how-can-i-uniquely-identify-a-git-repository - ID="`git rev-list --parents HEAD | tail -1`" + #ID="`git rev-list --parents HEAD | tail -1`" + ID="$PWD" # Display ID - echo $ID + #echo $ID # Create config folder mkdir -p $BASE/$ID # Check if we have a saved config - if [ ! -f "$BASE/$ID/config" ]; then + if [ ! -f "$BASE/$ID/$FILENAME" ]; then echo "No config for `pwd`, skipping" return fi # Make a backup - if ! diff .git/config $BASE/$ID/config &> /dev/null; then + if ! diff .git/config $BASE/$ID/$FILENAME &> /dev/null; then cp .git/config .git/config.$DATE else echo "Identical configs for `pwd`, skipping" @@ -113,7 +119,7 @@ function git_config_restore { fi # Restore - cp $BASE/$ID/config .git/config + cp $BASE/$ID/$FILENAME .git/config # Tell the user about the backup echo "Backup saved at $pwd/.git/config.$DATE" @@ -124,7 +130,8 @@ find -type d -name .git | while read repo; do # Get absolute folder PWD="`cd $repo/.. &> /dev/null && pwd`" - echo -n -e "Processing $PWD...\t" + #echo -n -e "Processing $PWD...\t" + echo "Processing $PWD..." ( cd $PWD |