Merge branch 'jh/maint-do-not-track-non-branches'
authorJunio C Hamano <gitster@pobox.com>
Tue, 15 Mar 2011 21:22:13 +0000 (14:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Mar 2011 21:22:13 +0000 (14:22 -0700)
* jh/maint-do-not-track-non-branches:
branch/checkout --track: Ensure that upstream branch is indeed a branch

1  2 
branch.c
t/t3200-branch.sh
t/t6040-tracking-info.sh
diff --combined branch.c
index dc23e954357c7e56d9232af7a8907ec4ed15b674,da5c03e56545b79cb92dd850ed09e81c21f9162f..c0c865a4b1b0fca038f32b77f2239d7987438ff5
+++ b/branch.c
@@@ -175,9 -175,14 +175,14 @@@ void create_branch(const char *head
                        die("Cannot setup tracking information; starting point is not a branch.");
                break;
        case 1:
-               /* Unique completion -- good, only if it is a real ref */
-               if (explicit_tracking && !strcmp(real_ref, "HEAD"))
-                       die("Cannot setup tracking information; starting point is not a branch.");
+               /* Unique completion -- good, only if it is a real branch */
+               if (prefixcmp(real_ref, "refs/heads/") &&
+                   prefixcmp(real_ref, "refs/remotes/")) {
+                       if (explicit_tracking)
+                               die("Cannot setup tracking information; starting point is not a branch.");
+                       else
+                               real_ref = NULL;
+               }
                break;
        default:
                die("Ambiguous object name: '%s'.", start_name);
  
  void remove_branch_state(void)
  {
 +      unlink(git_path("CHERRY_PICK_HEAD"));
        unlink(git_path("MERGE_HEAD"));
        unlink(git_path("MERGE_RR"));
        unlink(git_path("MERGE_MSG"));
diff --combined t/t3200-branch.sh
index f308235f5dd28da2c19d91dc63803312aacd2cda,55af032f2e325a0399186097fa3a59690a8a9449..78ce09f9d788203ebea280cc94c8098c9043311f
@@@ -26,17 -26,6 +26,17 @@@ test_expect_success 
       ! test -f .git/refs/heads/--help
  '
  
 +test_expect_success 'branch -h in broken repository' '
 +      mkdir broken &&
 +      (
 +              cd broken &&
 +              git init &&
 +              >.git/refs/heads/master &&
 +              test_expect_code 129 git branch -h >usage 2>&1
 +      ) &&
 +      grep "[Uu]sage" broken/usage
 +'
 +
  test_expect_success \
      'git branch abc should create a branch' \
      'git branch abc && test -f .git/refs/heads/abc'
@@@ -223,6 -212,11 +223,11 @@@ test_expect_success 
      'branch from non-branch HEAD w/--track causes failure' \
      'test_must_fail git branch --track my10 HEAD^'
  
+ test_expect_success \
+     'branch from tag w/--track causes failure' \
+     'git tag foobar &&
+      test_must_fail git branch --track my11 foobar'
  # Keep this test last, as it changes the current branch
  cat >expect <<EOF
  0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000    branch: Created from master
@@@ -488,6 -482,15 +493,15 @@@ test_expect_success 'autosetuprebase al
        test "z$(git config branch.myr20.rebase)" = z
  '
  
+ test_expect_success 'autosetuprebase always on detached HEAD' '
+       git config branch.autosetupmerge always &&
+       test_when_finished git checkout master &&
+       git checkout HEAD^0 &&
+       git branch my11 &&
+       test -z "$(git config branch.my11.remote)" &&
+       test -z "$(git config branch.my11.merge)"
+ '
  test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
        git config branch.autosetuprebase garbage &&
        test_must_fail git branch
diff --combined t/t6040-tracking-info.sh
index 1e0447f615c55ecf98ae341553ea60f10a956ae3,10bf3dee3f538b72f4f98d59f180a771b728b996..cb851326425be7a552a0624a5d7483244625a7ed
@@@ -60,7 -60,7 +60,7 @@@ test_expect_success 'checkout' 
  
  test_expect_success 'checkout with local tracked branch' '
        git checkout master &&
 -      git checkout follower >actual
 +      git checkout follower >actual &&
        grep "is ahead of" actual
  '
  
@@@ -74,20 -74,20 +74,20 @@@ test_expect_success 'status' 
        grep "have 1 and 1 different" actual
  '
  
- test_expect_success 'status when tracking lightweight tags' '
+ test_expect_success 'fail to track lightweight tags' '
        git checkout master &&
        git tag light &&
-       git branch --track lighttrack light >actual &&
-       grep "set up to track" actual &&
-       git checkout lighttrack
+       test_must_fail git branch --track lighttrack light >actual &&
+       test_must_fail grep "set up to track" actual &&
+       test_must_fail git checkout lighttrack
  '
  
- test_expect_success 'status when tracking annotated tags' '
+ test_expect_success 'fail to track annotated tags' '
        git checkout master &&
        git tag -m heavy heavy &&
-       git branch --track heavytrack heavy >actual &&
-       grep "set up to track" actual &&
-       git checkout heavytrack
+       test_must_fail git branch --track heavytrack heavy >actual &&
+       test_must_fail grep "set up to track" actual &&
+       test_must_fail git checkout heavytrack
  '
  
  test_expect_success 'setup tracking with branch --set-upstream on existing branch' '