diff options
author | Thomas Gummerer <t.gummerer@gmail.com> | 2017-11-29 20:04:50 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-12-06 17:47:35 (GMT) |
commit | 71d6682d8ca9870cbe457cf55c83402c33b41030 (patch) | |
tree | 23fe7176c9dc953f64acb55d96b852aded935a57 /t/t2025-worktree-add.sh | |
parent | 4e8533319760c1e9255c56c2059c721286dc8dab (diff) | |
download | git-71d6682d8ca9870cbe457cf55c83402c33b41030.zip git-71d6682d8ca9870cbe457cf55c83402c33b41030.tar.gz git-71d6682d8ca9870cbe457cf55c83402c33b41030.tar.bz2 |
worktree: add --guess-remote flag to add subcommand
Currently 'git worktree add <path>' creates a new branch named after the
basename of the <path>, that matches the HEAD of whichever worktree we
were on when calling "git worktree add <path>".
It's sometimes useful to have 'git worktree add <path> behave more like
the dwim machinery in 'git checkout <new-branch>', i.e. check if the new
branch name, derived from the basename of the <path>, uniquely matches
the branch name of a remote-tracking branch, and if so check out that
branch and set the upstream to the remote-tracking branch.
Add a new --guess-remote option that enables exactly that behaviour.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2025-worktree-add.sh')
-rwxr-xr-x | t/t2025-worktree-add.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh index 96ebc63..d25c774 100755 --- a/t/t2025-worktree-add.sh +++ b/t/t2025-worktree-add.sh @@ -384,4 +384,33 @@ test_expect_success '"add" <path> <branch> dwims' ' ) ' +test_expect_success 'git worktree add does not match remote' ' + test_when_finished rm -rf repo_a repo_b foo && + setup_remote_repo repo_a repo_b && + ( + cd repo_b && + git worktree add ../foo + ) && + ( + cd foo && + test_must_fail git config "branch.foo.remote" && + test_must_fail git config "branch.foo.merge" && + ! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo + ) +' + +test_expect_success 'git worktree add --guess-remote sets up tracking' ' + test_when_finished rm -rf repo_a repo_b foo && + setup_remote_repo repo_a repo_b && + ( + cd repo_b && + git worktree add --guess-remote ../foo + ) && + ( + cd foo && + test_branch_upstream foo repo_a foo && + test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo + ) +' + test_done |