]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'es/clone-shared-worktree'
authorJunio C Hamano <gitster@pobox.com>
Wed, 27 Dec 2017 19:16:28 +0000 (11:16 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Dec 2017 19:16:28 +0000 (11:16 -0800)
"git clone --shared" to borrow from a (secondary) worktree did not
work, even though "git clone --local" did.  Both are now accepted.

* es/clone-shared-worktree:
  clone: support 'clone --shared' from a worktree

1  2 
builtin/clone.c
t/t2025-worktree-add.sh

diff --cc builtin/clone.c
Simple merge
index 1285668cfce0bb0f9f7a62dcf3dd293d03be40b2,8f3e726d351b37fdd4f6e1cb9cb1d2f6a9400ea6..2b959449730e14dd4e650ce9115a463d71eedca4
@@@ -245,232 -198,10 +245,238 @@@ test_expect_success 'local clone from l
        ( cd here-clone && git fsck )
  '
  
+ test_expect_success 'local clone --shared from linked checkout' '
+       git -C bare worktree add --detach ../baretree &&
+       git clone --local --shared baretree bare-clone &&
+       grep /bare/ bare-clone/.git/objects/info/alternates
+ '
 +test_expect_success '"add" worktree with --no-checkout' '
 +      git worktree add --no-checkout -b swamp swamp &&
 +      ! test -e swamp/init.t &&
 +      git -C swamp reset --hard &&
 +      test_cmp init.t swamp/init.t
 +'
 +
 +test_expect_success '"add" worktree with --checkout' '
 +      git worktree add --checkout -b swmap2 swamp2 &&
 +      test_cmp init.t swamp2/init.t
 +'
 +
 +test_expect_success 'put a worktree under rebase' '
 +      git worktree add under-rebase &&
 +      (
 +              cd under-rebase &&
 +              set_fake_editor &&
 +              FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 +              git worktree list | grep "under-rebase.*detached HEAD"
 +      )
 +'
 +
 +test_expect_success 'add a worktree, checking out a rebased branch' '
 +      test_must_fail git worktree add new-rebase under-rebase &&
 +      ! test -d new-rebase
 +'
 +
 +test_expect_success 'checking out a rebased branch from another worktree' '
 +      git worktree add new-place &&
 +      test_must_fail git -C new-place checkout under-rebase
 +'
 +
 +test_expect_success 'not allow to delete a branch under rebase' '
 +      (
 +              cd under-rebase &&
 +              test_must_fail git branch -D under-rebase
 +      )
 +'
 +
 +test_expect_success 'rename a branch under rebase not allowed' '
 +      test_must_fail git branch -M under-rebase rebase-with-new-name
 +'
 +
 +test_expect_success 'check out from current worktree branch ok' '
 +      (
 +              cd under-rebase &&
 +              git checkout under-rebase &&
 +              git checkout - &&
 +              git rebase --abort
 +      )
 +'
 +
 +test_expect_success 'checkout a branch under bisect' '
 +      git worktree add under-bisect &&
 +      (
 +              cd under-bisect &&
 +              git bisect start &&
 +              git bisect bad &&
 +              git bisect good HEAD~2 &&
 +              git worktree list | grep "under-bisect.*detached HEAD" &&
 +              test_must_fail git worktree add new-bisect under-bisect &&
 +              ! test -d new-bisect
 +      )
 +'
 +
 +test_expect_success 'rename a branch under bisect not allowed' '
 +      test_must_fail git branch -M under-bisect bisect-with-new-name
 +'
 +# Is branch "refs/heads/$1" set to pull from "$2/$3"?
 +test_branch_upstream () {
 +      printf "%s\n" "$2" "refs/heads/$3" >expect.upstream &&
 +      {
 +              git config "branch.$1.remote" &&
 +              git config "branch.$1.merge"
 +      } >actual.upstream &&
 +      test_cmp expect.upstream actual.upstream
 +}
 +
 +test_expect_success '--track sets up tracking' '
 +      test_when_finished rm -rf track &&
 +      git worktree add --track -b track track master &&
 +      test_branch_upstream track . master
 +'
 +
 +# setup remote repository $1 and repository $2 with $1 set up as
 +# remote.  The remote has two branches, master and foo.
 +setup_remote_repo () {
 +      git init $1 &&
 +      (
 +              cd $1 &&
 +              test_commit $1_master &&
 +              git checkout -b foo &&
 +              test_commit upstream_foo
 +      ) &&
 +      git init $2 &&
 +      (
 +              cd $2 &&
 +              test_commit $2_master &&
 +              git remote add $1 ../$1 &&
 +              git config remote.$1.fetch \
 +                      "refs/heads/*:refs/remotes/$1/*" &&
 +              git fetch --all
 +      )
 +}
 +
 +test_expect_success '--no-track avoids setting up tracking' '
 +      test_when_finished rm -rf repo_upstream repo_local foo &&
 +      setup_remote_repo repo_upstream repo_local &&
 +      (
 +              cd repo_local &&
 +              git worktree add --no-track -b foo ../foo repo_upstream/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_upstream/foo refs/heads/foo
 +      )
 +'
 +
 +test_expect_success '"add" <path> <non-existent-branch> fails' '
 +      test_must_fail git worktree add foo non-existent
 +'
 +
 +test_expect_success '"add" <path> <branch> dwims' '
 +      test_when_finished rm -rf repo_upstream repo_dwim foo &&
 +      setup_remote_repo repo_upstream repo_dwim &&
 +      git init repo_dwim &&
 +      (
 +              cd repo_dwim &&
 +              git worktree add ../foo foo
 +      ) &&
 +      (
 +              cd foo &&
 +              test_branch_upstream foo repo_upstream foo &&
 +              test_cmp_rev refs/remotes/repo_upstream/foo refs/heads/foo
 +      )
 +'
 +
 +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_expect_success 'git worktree add with worktree.guessRemote sets up tracking' '
 +      test_when_finished rm -rf repo_a repo_b foo &&
 +      setup_remote_repo repo_a repo_b &&
 +      (
 +              cd repo_b &&
 +              git config worktree.guessRemote true &&
 +              git worktree add ../foo
 +      ) &&
 +      (
 +              cd foo &&
 +              test_branch_upstream foo repo_a foo &&
 +              test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
 +      )
 +'
 +
 +test_expect_success 'git worktree --no-guess-remote option overrides config' '
 +      test_when_finished rm -rf repo_a repo_b foo &&
 +      setup_remote_repo repo_a repo_b &&
 +      (
 +              cd repo_b &&
 +              git config worktree.guessRemote true &&
 +              git worktree add --no-guess-remote ../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
 +      )
 +'
 +
 +post_checkout_hook () {
 +      test_when_finished "rm -f .git/hooks/post-checkout" &&
 +      mkdir -p .git/hooks &&
 +      write_script .git/hooks/post-checkout <<-\EOF
 +      echo $* >hook.actual
 +      EOF
 +}
 +
 +test_expect_success '"add" invokes post-checkout hook (branch)' '
 +      post_checkout_hook &&
 +      printf "%s %s 1\n" $_z40 $(git rev-parse HEAD) >hook.expect &&
 +      git worktree add gumby &&
 +      test_cmp hook.expect hook.actual
 +'
 +
 +test_expect_success '"add" invokes post-checkout hook (detached)' '
 +      post_checkout_hook &&
 +      printf "%s %s 1\n" $_z40 $(git rev-parse HEAD) >hook.expect &&
 +      git worktree add --detach grumpy &&
 +      test_cmp hook.expect hook.actual
 +'
 +
 +test_expect_success '"add --no-checkout" suppresses post-checkout hook' '
 +      post_checkout_hook &&
 +      rm -f hook.actual &&
 +      git worktree add --no-checkout gloopy &&
 +      test_path_is_missing hook.actual
 +'
 +
  test_done