Skip to content

Commit

Permalink
Don't use git tags in pull
Browse files Browse the repository at this point in the history
As seen in #225, this approach was more complicated
than it needed to be and caused confusion for users.
  • Loading branch information
yut23 committed Sep 25, 2024
1 parent ea9511a commit b9b587c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
9 changes: 8 additions & 1 deletion bin/homeshick
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
24 changes: 5 additions & 19 deletions lib/commands/pull.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

BEFORE_PULL_TAG=__homeshick-before-pull__
pull() {
[[ ! $1 ]] && help_err pull
local castle=$1
Expand All @@ -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"
Expand All @@ -36,7 +26,6 @@ pull() {
err "$EX_SOFTWARE" "Unable update submodules for $repo. Git says:" "$git_out"
fi
success
trap - EXIT
return "$EX_SUCCESS"
}

Expand All @@ -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
Expand Down

0 comments on commit b9b587c

Please sign in to comment.