From b9b587ccb4c4c05f2045f73cbeb508e60fb4a409 Mon Sep 17 00:00:00 2001 From: yut23 Date: Tue, 24 Sep 2024 22:58:34 -0400 Subject: [PATCH] Don't use git tags in pull As seen in andsens/homeshick#225, this approach was more complicated than it needed to be and caused confusion for users. --- bin/homeshick | 9 ++++++++- lib/commands/pull.sh | 24 +++++------------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/bin/homeshick b/bin/homeshick index 82f7322..5e2e905 100755 --- a/bin/homeshick +++ b/bin/homeshick @@ -171,6 +171,7 @@ case $cmd in cd) help cd ;; # cd is implemented in the homeshick.{sh,csh} helper script. help) help $help_cmd ;; *) + declare -a pull_completed for param in "${params[@]}"; do case $cmd in clone) @@ -182,7 +183,13 @@ case $cmd in refresh) (refresh $threshhold "$param") ;; pull) - (pull "$param") && pull_completed+=("$param") ;; + prev_hash=$(cd "$repos/$param" && git rev-parse HEAD) + (pull "$param") + result=$? + curr_hash=$(cd "$repos/$param" && git rev-parse HEAD) + [[ "$prev_hash" != "$curr_hash" ]] && pull_completed+=("$param") + (exit $result) + ;; symlink|link) symlink "$param" ;; track) diff --git a/lib/commands/pull.sh b/lib/commands/pull.sh index cc3b138..5e7360b 100644 --- a/lib/commands/pull.sh +++ b/lib/commands/pull.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -BEFORE_PULL_TAG=__homeshick-before-pull__ pull() { [[ ! $1 ]] && help_err pull local castle=$1 @@ -14,15 +13,6 @@ pull() { return "$EX_SUCCESS" fi - # this tag is exceedingly unlikely to already exist, but if it does, error - # out and let the user resolve it - (cd "$repo" && git rev-parse --verify "refs/tags/$BEFORE_PULL_TAG" &>/dev/null) && \ - err "$EX_DATAERR" "Pull marker tag ($BEFORE_PULL_TAG) already exists in $repo. Please resolve this before pulling." - # make a tag at the current commit, so we can compare against it below - (cd "$repo" && git tag --no-sign "$BEFORE_PULL_TAG" 2>&1) - # remove the tag if one of the git operations fails - trap 'cd "$repo" && git tag -d "$BEFORE_PULL_TAG" &>/dev/null' EXIT - local git_out git_out=$(cd "$repo" && git pull 2>&1) || \ err "$EX_SOFTWARE" "Unable to pull $repo. Git says:" "$git_out" @@ -36,7 +26,6 @@ pull() { err "$EX_SOFTWARE" "Unable update submodules for $repo. Git says:" "$git_out" fi success - trap - EXIT return "$EX_SUCCESS" } @@ -46,17 +35,14 @@ symlink_new_files() { local castle=$1 shift local repo="$repos/$castle" - local git_out - git_out=$(cd "$repo" && git diff --name-only --diff-filter=AR "$BEFORE_PULL_TAG" HEAD -- home 2>/dev/null | wc -l 2>&1) - local result=$? - # Remove the tag before doing anything else - (cd "$repo" && git tag -d "$BEFORE_PULL_TAG" &>/dev/null) - if [[ $result -ne 0 ]]; then - continue # Ignore errors, this operation is not mission critical - fi if [[ ! -d $repo/home ]]; then continue; fi + # @{1} refers to the previous reflog entry on the current branch, which + # will be right before the pull + if ! git_out=$(cd "$repo" && git diff --name-only --diff-filter=AR '@{1}' HEAD -- home 2>/dev/null | wc -l 2>&1); then + continue # Ignore errors, this operation is not mission critical + fi if [[ $git_out -gt 0 ]]; then updated_castles+=("$castle") fi