use branch revision during worktree add (v4)
This is a port of the v3 commit 2c3bb035f6
This commit is contained in:
parent
4d286fc44f
commit
a91777288a
|
|
@ -896,11 +896,6 @@ func (git *repoSync) AddWorktreeAndSwap(ctx context.Context, hash string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
// GC clone
|
||||
if _, err := git.run.Run(ctx, git.root, git.cmd, "gc", "--prune=all"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Make a worktree for this exact git hash.
|
||||
worktreePath := filepath.Join(git.root, hash)
|
||||
|
||||
|
|
@ -912,12 +907,17 @@ func (git *repoSync) AddWorktreeAndSwap(ctx context.Context, hash string) error
|
|||
return err
|
||||
}
|
||||
|
||||
_, err := git.run.Run(ctx, git.root, git.cmd, "worktree", "add", worktreePath, "origin/"+git.branch, "--no-checkout")
|
||||
_, err := git.run.Run(ctx, git.root, git.cmd, "worktree", "add", "--detach", worktreePath, hash, "--no-checkout")
|
||||
git.log.V(0).Info("adding worktree", "path", worktreePath, "branch", fmt.Sprintf("origin/%s", git.branch))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// GC clone
|
||||
if _, err := git.run.Run(ctx, git.root, git.cmd, "gc", "--prune=all"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// The .git file in the worktree directory holds a reference to
|
||||
// /git/.git/worktrees/<worktree-dir-name>. Replace it with a reference
|
||||
// using relative paths, so that other containers can use a different volume
|
||||
|
|
|
|||
36
test_e2e.sh
36
test_e2e.sh
|
|
@ -553,6 +553,42 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
|
|||
# Wrap up
|
||||
pass
|
||||
|
||||
##############################################
|
||||
# Test switching branch after depth=1 checkout
|
||||
##############################################
|
||||
testcase "branch-switch"
|
||||
# First sync
|
||||
echo "$TESTCASE" > "$REPO"/file
|
||||
git -C "$REPO" commit -qam "$TESTCASE"
|
||||
GIT_SYNC \
|
||||
--one-time \
|
||||
--repo="file://$REPO" \
|
||||
--branch=e2e-branch \
|
||||
--depth=1 \
|
||||
--root="$ROOT" \
|
||||
--link="link" \
|
||||
> "$DIR"/log."$TESTCASE" 2>&1
|
||||
assert_link_exists "$ROOT"/link
|
||||
assert_file_exists "$ROOT"/link/file
|
||||
assert_file_eq "$ROOT"/link/file "$TESTCASE"
|
||||
BRANCH="${TESTCASE}2"
|
||||
git -C "$REPO" checkout -q -b $BRANCH
|
||||
echo "$TESTCASE 2" > "$REPO"/file
|
||||
git -C "$REPO" commit -qam "$TESTCASE 2"
|
||||
GIT_SYNC \
|
||||
--one-time \
|
||||
--repo="file://$REPO" \
|
||||
--branch=$BRANCH \
|
||||
--rev=HEAD \
|
||||
--root="$ROOT" \
|
||||
--link="link" \
|
||||
>> "$DIR"/log."$TESTCASE" 2>&1
|
||||
assert_link_exists "$ROOT"/link
|
||||
assert_file_exists "$ROOT"/link/file
|
||||
assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
|
||||
# Wrap up
|
||||
pass
|
||||
|
||||
##############################################
|
||||
# Test tag syncing
|
||||
##############################################
|
||||
|
|
|
|||
Loading…
Reference in New Issue