Skip to content

Commit 7b2685e

Browse files
committed
Merge branch 'dl/branch-cleanup'
Code clean-up around "git branch" with a minor bugfix. * dl/branch-cleanup: branch: don't mix --edit-description t3200: test for specific errors t3200: rename "expected" to "expect"
2 parents eb52351 + dc44639 commit 7b2685e

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
693693
list = 1;
694694

695695
if (!!delete + !!rename + !!copy + !!new_upstream + !!show_current +
696-
list + unset_upstream > 1)
696+
list + edit_description + unset_upstream > 1)
697697
usage_with_options(builtin_branch_usage, options);
698698

699699
if (filter.abbrev == -1)

t/t3200-branch.sh

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ test_expect_success 'git branch --list -v with --abbrev' '
323323

324324
test_expect_success 'git branch --column' '
325325
COLUMNS=81 git branch --column=column >actual &&
326-
cat >expected <<\EOF &&
326+
cat >expect <<\EOF &&
327327
a/b/c bam foo l * master mb o/o q
328328
abc bar j/k m/m master2 n o/p r
329329
EOF
330-
test_cmp expected actual
330+
test_cmp expect actual
331331
'
332332

333333
test_expect_success 'git branch --column with an extremely long branch name' '
@@ -336,7 +336,7 @@ test_expect_success 'git branch --column with an extremely long branch name' '
336336
test_when_finished "git branch -d $long" &&
337337
git branch $long &&
338338
COLUMNS=80 git branch --column=column >actual &&
339-
cat >expected <<EOF &&
339+
cat >expect <<EOF &&
340340
a/b/c
341341
abc
342342
bam
@@ -355,7 +355,7 @@ test_expect_success 'git branch --column with an extremely long branch name' '
355355
r
356356
$long
357357
EOF
358-
test_cmp expected actual
358+
test_cmp expect actual
359359
'
360360

361361
test_expect_success 'git branch with column.*' '
@@ -364,11 +364,11 @@ test_expect_success 'git branch with column.*' '
364364
COLUMNS=80 git branch >actual &&
365365
git config --unset column.branch &&
366366
git config --unset column.ui &&
367-
cat >expected <<\EOF &&
367+
cat >expect <<\EOF &&
368368
a/b/c bam foo l * master mb o/o q
369369
abc bar j/k m/m master2 n o/p r
370370
EOF
371-
test_cmp expected actual
371+
test_cmp expect actual
372372
'
373373

374374
test_expect_success 'git branch --column -v should fail' '
@@ -379,7 +379,7 @@ test_expect_success 'git branch -v with column.ui ignored' '
379379
git config column.ui column &&
380380
COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
381381
git config --unset column.ui &&
382-
cat >expected <<\EOF &&
382+
cat >expect <<\EOF &&
383383
a/b/c
384384
abc
385385
bam
@@ -397,7 +397,7 @@ test_expect_success 'git branch -v with column.ui ignored' '
397397
q
398398
r
399399
EOF
400-
test_cmp expected actual
400+
test_cmp expect actual
401401
'
402402

403403
mv .git/config .git/config-saved
@@ -835,32 +835,42 @@ test_expect_success 'branch from tag w/--track causes failure' '
835835
'
836836

837837
test_expect_success '--set-upstream-to fails on multiple branches' '
838-
test_must_fail git branch --set-upstream-to master a b c
838+
echo "fatal: too many arguments to set new upstream" >expect &&
839+
test_must_fail git branch --set-upstream-to master a b c 2>err &&
840+
test_i18ncmp expect err
839841
'
840842

841843
test_expect_success '--set-upstream-to fails on detached HEAD' '
842844
git checkout HEAD^{} &&
843-
test_must_fail git branch --set-upstream-to master &&
844-
git checkout -
845+
test_when_finished git checkout - &&
846+
echo "fatal: could not set upstream of HEAD to master when it does not point to any branch." >expect &&
847+
test_must_fail git branch --set-upstream-to master 2>err &&
848+
test_i18ncmp expect err
845849
'
846850

847851
test_expect_success '--set-upstream-to fails on a missing dst branch' '
848-
test_must_fail git branch --set-upstream-to master does-not-exist
852+
echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect &&
853+
test_must_fail git branch --set-upstream-to master does-not-exist 2>err &&
854+
test_i18ncmp expect err
849855
'
850856

851857
test_expect_success '--set-upstream-to fails on a missing src branch' '
852-
test_must_fail git branch --set-upstream-to does-not-exist master
858+
test_must_fail git branch --set-upstream-to does-not-exist master 2>err &&
859+
test_i18ngrep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err
853860
'
854861

855862
test_expect_success '--set-upstream-to fails on a non-ref' '
856-
test_must_fail git branch --set-upstream-to HEAD^{}
863+
echo "fatal: Cannot setup tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch." >expect &&
864+
test_must_fail git branch --set-upstream-to HEAD^{} 2>err &&
865+
test_i18ncmp expect err
857866
'
858867

859868
test_expect_success '--set-upstream-to fails on locked config' '
860869
test_when_finished "rm -f .git/config.lock" &&
861870
>.git/config.lock &&
862871
git branch locked &&
863-
test_must_fail git branch --set-upstream-to locked
872+
test_must_fail git branch --set-upstream-to locked 2>err &&
873+
test_i18ngrep "could not lock config file .git/config: File exists" err
864874
'
865875

866876
test_expect_success 'use --set-upstream-to modify HEAD' '
@@ -881,14 +891,17 @@ test_expect_success 'use --set-upstream-to modify a particular branch' '
881891
'
882892

883893
test_expect_success '--unset-upstream should fail if given a non-existent branch' '
884-
test_must_fail git branch --unset-upstream i-dont-exist
894+
echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect &&
895+
test_must_fail git branch --unset-upstream i-dont-exist 2>err &&
896+
test_i18ncmp expect err
885897
'
886898

887899
test_expect_success '--unset-upstream should fail if config is locked' '
888900
test_when_finished "rm -f .git/config.lock" &&
889901
git branch --set-upstream-to locked &&
890902
>.git/config.lock &&
891-
test_must_fail git branch --unset-upstream
903+
test_must_fail git branch --unset-upstream 2>err &&
904+
test_i18ngrep "could not lock config file .git/config: File exists" err
892905
'
893906

894907
test_expect_success 'test --unset-upstream on HEAD' '
@@ -900,17 +913,23 @@ test_expect_success 'test --unset-upstream on HEAD' '
900913
test_must_fail git config branch.master.remote &&
901914
test_must_fail git config branch.master.merge &&
902915
# fail for a branch without upstream set
903-
test_must_fail git branch --unset-upstream
916+
echo "fatal: Branch '"'"'master'"'"' has no upstream information" >expect &&
917+
test_must_fail git branch --unset-upstream 2>err &&
918+
test_i18ncmp expect err
904919
'
905920

906921
test_expect_success '--unset-upstream should fail on multiple branches' '
907-
test_must_fail git branch --unset-upstream a b c
922+
echo "fatal: too many arguments to unset upstream" >expect &&
923+
test_must_fail git branch --unset-upstream a b c 2>err &&
924+
test_i18ncmp expect err
908925
'
909926

910927
test_expect_success '--unset-upstream should fail on detached HEAD' '
911928
git checkout HEAD^{} &&
912-
test_must_fail git branch --unset-upstream &&
913-
git checkout -
929+
test_when_finished git checkout - &&
930+
echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect &&
931+
test_must_fail git branch --unset-upstream 2>err &&
932+
test_i18ncmp expect err
914933
'
915934

916935
test_expect_success 'test --unset-upstream on a particular branch' '
@@ -922,17 +941,17 @@ test_expect_success 'test --unset-upstream on a particular branch' '
922941
'
923942

924943
test_expect_success 'disabled option --set-upstream fails' '
925-
test_must_fail git branch --set-upstream origin/master
944+
test_must_fail git branch --set-upstream origin/master
926945
'
927946

928947
test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
929948
git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
930-
cat >expected <<-\EOF &&
949+
cat >expect <<-\EOF &&
931950
warning: Not setting branch my13 as its own upstream.
932951
EOF
933952
test_expect_code 1 git config branch.my13.remote &&
934953
test_expect_code 1 git config branch.my13.merge &&
935-
test_i18ncmp expected actual
954+
test_i18ncmp expect actual
936955
'
937956

938957
# Keep this test last, as it changes the current branch

0 commit comments

Comments
 (0)