Code

Catch invalid --depth option passed to clone or fetch
[git.git] / t / t3200-branch.sh
index 7a83fbfe4f6b47dc5dbaa3df59c8633ae5c2c8f8..9e69c8c926620f06343e64e7b3aa3e4ada5a6b69 100755 (executable)
@@ -14,10 +14,10 @@ test_expect_success \
     'prepare a trivial repository' \
     'echo Hello > A &&
      git update-index --add A &&
-     git-commit -m "Initial commit." &&
+     git commit -m "Initial commit." &&
      echo World >> A &&
      git update-index --add A &&
-     git-commit -m "Second commit." &&
+     git commit -m "Second commit." &&
      HEAD=$(git rev-parse --verify HEAD)'
 
 test_expect_success \
@@ -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'
@@ -35,7 +46,7 @@ test_expect_success \
     'git branch a/b/c && test -f .git/refs/heads/a/b/c'
 
 cat >expect <<EOF
-0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
+$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
 EOF
 test_expect_success \
     'git branch -l d/e/f should create a branch and a log' \
@@ -43,7 +54,7 @@ test_expect_success \
      git branch -l d/e/f &&
         test -f .git/refs/heads/d/e/f &&
         test -f .git/logs/refs/heads/d/e/f &&
-        diff expect .git/logs/refs/heads/d/e/f'
+        test_cmp expect .git/logs/refs/heads/d/e/f'
 
 test_expect_success \
     'git branch -d d/e/f should delete a branch and a log' \
@@ -112,7 +123,16 @@ test_expect_success 'config information was renamed, too' \
        "test $(git config branch.s.dummy) = Hello &&
         test_must_fail git config branch.s/s/dummy"
 
-test_expect_success \
+test_expect_success 'renaming a symref is not allowed' \
+'
+       git symbolic-ref refs/heads/master2 refs/heads/master &&
+       test_must_fail git branch -m master2 master3 &&
+       git symbolic-ref refs/heads/master2 &&
+       test -f .git/refs/heads/master &&
+       ! test -f .git/refs/heads/master3
+'
+
+test_expect_success SYMLINKS \
     'git branch -m u v should fail when the reflog for u is a symlink' '
      git branch -l u &&
      mv .git/logs/refs/heads/u real-u &&
@@ -123,7 +143,7 @@ test_expect_success \
 test_expect_success 'test tracking setup via --track' \
     'git config remote.local.url . &&
      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+     (git show-ref -q refs/remotes/local/master || git fetch local) &&
      git branch --track my1 local/master &&
      test $(git config branch.my1.remote) = local &&
      test $(git config branch.my1.merge) = refs/heads/master'
@@ -131,7 +151,7 @@ test_expect_success 'test tracking setup via --track' \
 test_expect_success 'test tracking setup (non-wildcard, matching)' \
     'git config remote.local.url . &&
      git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
-     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+     (git show-ref -q refs/remotes/local/master || git fetch local) &&
      git branch --track my4 local/master &&
      test $(git config branch.my4.remote) = local &&
      test $(git config branch.my4.merge) = refs/heads/master'
@@ -139,7 +159,7 @@ test_expect_success 'test tracking setup (non-wildcard, matching)' \
 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
     'git config remote.local.url . &&
      git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
-     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+     (git show-ref -q refs/remotes/local/master || git fetch local) &&
      git branch --track my5 local/master &&
      ! test "$(git config branch.my5.remote)" = local &&
      ! test "$(git config branch.my5.merge)" = refs/heads/master'
@@ -148,7 +168,7 @@ test_expect_success 'test tracking setup via config' \
     'git config branch.autosetupmerge true &&
      git config remote.local.url . &&
      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+     (git show-ref -q refs/remotes/local/master || git fetch local) &&
      git branch my3 local/master &&
      test $(git config branch.my3.remote) = local &&
      test $(git config branch.my3.merge) = refs/heads/master'
@@ -157,7 +177,7 @@ test_expect_success 'test overriding tracking setup via --no-track' \
     'git config branch.autosetupmerge true &&
      git config remote.local.url . &&
      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+     (git show-ref -q refs/remotes/local/master || git fetch local) &&
      git branch --no-track my2 local/master &&
      git config branch.autosetupmerge false &&
      ! test "$(git config branch.my2.remote)" = local &&
@@ -173,7 +193,7 @@ test_expect_success 'no tracking without .fetch entries' \
 test_expect_success 'test tracking setup via --track but deeper' \
     'git config remote.local.url . &&
      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
+     (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
      git branch --track my7 local/o/o &&
      test "$(git config branch.my7.remote)" = local &&
      test "$(git config branch.my7.merge)" = refs/heads/o/o'
@@ -185,7 +205,10 @@ test_expect_success 'test deleting branch deletes branch config' \
 
 test_expect_success 'test deleting branch without config' \
     'git branch my7 s &&
-     test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
+     sha1=$(git rev-parse my7 | cut -c 1-7) &&
+     echo "Deleted branch my7 (was $sha1)." >expect &&
+     git branch -d my7 >actual 2>&1 &&
+     test_i18ncmp expect actual'
 
 test_expect_success 'test --track without .fetch entries' \
     'git branch --track my8 &&
@@ -202,17 +225,43 @@ 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
+$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
 EOF
 test_expect_success \
     'git checkout -b g/h/i -l should create a branch and a log' \
        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
-     git-checkout -b g/h/i -l master &&
+     git checkout -b g/h/i -l master &&
         test -f .git/refs/heads/g/h/i &&
         test -f .git/logs/refs/heads/g/h/i &&
-        diff expect .git/logs/refs/heads/g/h/i'
+        test_cmp expect .git/logs/refs/heads/g/h/i'
+
+test_expect_success 'checkout -b makes reflog by default' '
+       git checkout master &&
+       git config --unset core.logAllRefUpdates &&
+       git checkout -b alpha &&
+       git rev-parse --verify alpha@{0}
+'
+
+test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
+       git checkout master &&
+       git config core.logAllRefUpdates false &&
+       git checkout -b beta &&
+       test_must_fail git rev-parse --verify beta@{0}
+'
+
+test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
+       git checkout master &&
+       git checkout -lb gamma &&
+       git config --unset core.logAllRefUpdates &&
+       git rev-parse --verify gamma@{0}
+'
 
 test_expect_success 'avoid ambiguous track' '
        git config branch.autosetupmerge true &&
@@ -228,7 +277,7 @@ test_expect_success 'autosetuprebase local on a tracked local branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase local &&
-       (git show-ref -q refs/remotes/local/o || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/o || git fetch local) &&
        git branch mybase &&
        git branch --track myr1 mybase &&
        test "$(git config branch.myr1.remote)" = . &&
@@ -240,7 +289,7 @@ test_expect_success 'autosetuprebase always on a tracked local branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase always &&
-       (git show-ref -q refs/remotes/local/o || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/o || git fetch local) &&
        git branch mybase2 &&
        git branch --track myr2 mybase &&
        test "$(git config branch.myr2.remote)" = . &&
@@ -252,7 +301,7 @@ test_expect_success 'autosetuprebase remote on a tracked local branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase remote &&
-       (git show-ref -q refs/remotes/local/o || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/o || git fetch local) &&
        git branch mybase3 &&
        git branch --track myr3 mybase2 &&
        test "$(git config branch.myr3.remote)" = . &&
@@ -264,7 +313,7 @@ test_expect_success 'autosetuprebase never on a tracked local branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase never &&
-       (git show-ref -q refs/remotes/local/o || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/o || git fetch local) &&
        git branch mybase4 &&
        git branch --track myr4 mybase2 &&
        test "$(git config branch.myr4.remote)" = . &&
@@ -276,7 +325,7 @@ test_expect_success 'autosetuprebase local on a tracked remote branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase local &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --track myr5 local/master &&
        test "$(git config branch.myr5.remote)" = local &&
        test "$(git config branch.myr5.merge)" = refs/heads/master &&
@@ -287,7 +336,7 @@ test_expect_success 'autosetuprebase never on a tracked remote branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase never &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --track myr6 local/master &&
        test "$(git config branch.myr6.remote)" = local &&
        test "$(git config branch.myr6.merge)" = refs/heads/master &&
@@ -298,7 +347,7 @@ test_expect_success 'autosetuprebase remote on a tracked remote branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase remote &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --track myr7 local/master &&
        test "$(git config branch.myr7.remote)" = local &&
        test "$(git config branch.myr7.merge)" = refs/heads/master &&
@@ -309,7 +358,7 @@ test_expect_success 'autosetuprebase always on a tracked remote branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        git config branch.autosetuprebase remote &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --track myr8 local/master &&
        test "$(git config branch.myr8.remote)" = local &&
        test "$(git config branch.myr8.merge)" = refs/heads/master &&
@@ -320,7 +369,7 @@ test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
        git config --unset branch.autosetuprebase &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --track myr9 local/master &&
        test "$(git config branch.myr9.remote)" = local &&
        test "$(git config branch.myr9.merge)" = refs/heads/master &&
@@ -330,7 +379,7 @@ test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/o || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/o || git fetch local) &&
        git branch mybase10 &&
        git branch --track myr10 mybase2 &&
        test "$(git config branch.myr10.remote)" = . &&
@@ -341,7 +390,7 @@ test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr11 mybase2 &&
        test "z$(git config branch.myr11.remote)" = z &&
        test "z$(git config branch.myr11.merge)" = z &&
@@ -351,7 +400,7 @@ test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr12 local/master &&
        test "z$(git config branch.myr12.remote)" = z &&
        test "z$(git config branch.myr12.merge)" = z &&
@@ -362,7 +411,7 @@ test_expect_success 'autosetuprebase never on an untracked local branch' '
        git config branch.autosetuprebase never &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr13 mybase2 &&
        test "z$(git config branch.myr13.remote)" = z &&
        test "z$(git config branch.myr13.merge)" = z &&
@@ -373,7 +422,7 @@ test_expect_success 'autosetuprebase local on an untracked local branch' '
        git config branch.autosetuprebase local &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr14 mybase2 &&
        test "z$(git config branch.myr14.remote)" = z &&
        test "z$(git config branch.myr14.merge)" = z &&
@@ -384,7 +433,7 @@ test_expect_success 'autosetuprebase remote on an untracked local branch' '
        git config branch.autosetuprebase remote &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr15 mybase2 &&
        test "z$(git config branch.myr15.remote)" = z &&
        test "z$(git config branch.myr15.merge)" = z &&
@@ -395,7 +444,7 @@ test_expect_success 'autosetuprebase always on an untracked local branch' '
        git config branch.autosetuprebase always &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr16 mybase2 &&
        test "z$(git config branch.myr16.remote)" = z &&
        test "z$(git config branch.myr16.merge)" = z &&
@@ -406,7 +455,7 @@ test_expect_success 'autosetuprebase never on an untracked remote branch' '
        git config branch.autosetuprebase never &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr17 local/master &&
        test "z$(git config branch.myr17.remote)" = z &&
        test "z$(git config branch.myr17.merge)" = z &&
@@ -417,7 +466,7 @@ test_expect_success 'autosetuprebase local on an untracked remote branch' '
        git config branch.autosetuprebase local &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr18 local/master &&
        test "z$(git config branch.myr18.remote)" = z &&
        test "z$(git config branch.myr18.merge)" = z &&
@@ -428,7 +477,7 @@ test_expect_success 'autosetuprebase remote on an untracked remote branch' '
        git config branch.autosetuprebase remote &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr19 local/master &&
        test "z$(git config branch.myr19.remote)" = z &&
        test "z$(git config branch.myr19.merge)" = z &&
@@ -439,13 +488,22 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' '
        git config branch.autosetuprebase always &&
        git config remote.local.url . &&
        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-       (git show-ref -q refs/remotes/local/master || git-fetch local) &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
        git branch --no-track myr20 local/master &&
        test "z$(git config branch.myr20.remote)" = z &&
        test "z$(git config branch.myr20.merge)" = z &&
        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
@@ -458,4 +516,30 @@ test_expect_success 'detect misconfigured autosetuprebase (no value)' '
        git config --unset branch.autosetuprebase
 '
 
+test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
+       git checkout my9 &&
+       git config --unset branch.my8.merge &&
+       test_must_fail git branch -d my8
+'
+
+test_expect_success 'attempt to delete a branch merged to its base' '
+       # we are on my9 which is the initial commit; traditionally
+       # we would not have allowed deleting my8 that is not merged
+       # to my9, but it is set to track master that already has my8
+       git config branch.my8.merge refs/heads/master &&
+       git branch -d my8
+'
+
+test_expect_success 'attempt to delete a branch merged to its base' '
+       git checkout master &&
+       echo Third >>A &&
+       git commit -m "Third commit" A &&
+       git branch -t my10 my9 &&
+       git branch -f my10 HEAD^ &&
+       # we are on master which is at the third commit, and my10
+       # is behind us, so traditionally we would have allowed deleting
+       # it; but my10 is set to track my9 that is further behind.
+       test_must_fail git branch -d my10
+'
+
 test_done