diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index ca1ca54..0d99754 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -602,7 +602,7 @@ func addWorktreeAndSwap(ctx context.Context, gitRoot, dest, branch, rev string, } // Make a worktree for this exact git hash. - worktreePath := filepath.Join(gitRoot, "rev-"+hash) + worktreePath := filepath.Join(gitRoot, hash) _, err := runCommand(ctx, gitRoot, *flGitCmd, "worktree", "add", worktreePath, "origin/"+branch) log.V(0).Info("adding worktree", "path", worktreePath, "branch", fmt.Sprintf("origin/%s", branch)) if err != nil { diff --git a/test_e2e.sh b/test_e2e.sh index 135f2e2..44b86d2 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -33,6 +33,13 @@ function assert_link_exists() { fi } +function assert_link_eq() { + if [[ $(readlink "$1") == "$2" ]]; then + return + fi + fail "link $1 does not point to '$2': $(readlink $1)" +} + function assert_file_exists() { if ! [[ -f "$1" ]]; then fail "$1 does not exist" @@ -255,6 +262,38 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Wrap up pass +############################################## +# Test readlink +############################################## +testcase "readlink" +# First sync +echo "$TESTCASE 1" > "$REPO"/file +git -C "$REPO" commit -qam "$TESTCASE 1" +GIT_SYNC \ + --wait=0.1 \ + --repo="file://$REPO" \ + --branch=e2e-branch \ + --rev=HEAD \ + --root="$ROOT" \ + --dest="link" \ + > "$DIR"/log."$TESTCASE" 2>&1 & +sleep 3 +assert_link_exists "$ROOT"/link +assert_link_eq "$ROOT"/link $(git -C "$REPO" rev-parse HEAD) +# Move HEAD forward +echo "$TESTCASE 2" > "$REPO"/file +git -C "$REPO" commit -qam "$TESTCASE 2" +sleep 3 +assert_link_exists "$ROOT"/link +assert_link_eq "$ROOT"/link $(git -C "$REPO" rev-parse HEAD) +# Move HEAD backward +git -C "$REPO" reset -q --hard HEAD^ +sleep 3 +assert_link_exists "$ROOT"/link +assert_link_eq "$ROOT"/link $(git -C "$REPO" rev-parse HEAD) +# Wrap up +pass + ############################################## # Test branch syncing ##############################################