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"
This commit is contained in:
@ -693,7 +693,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
|||||||
list = 1;
|
list = 1;
|
||||||
|
|
||||||
if (!!delete + !!rename + !!copy + !!new_upstream + !!show_current +
|
if (!!delete + !!rename + !!copy + !!new_upstream + !!show_current +
|
||||||
list + unset_upstream > 1)
|
list + edit_description + unset_upstream > 1)
|
||||||
usage_with_options(builtin_branch_usage, options);
|
usage_with_options(builtin_branch_usage, options);
|
||||||
|
|
||||||
if (filter.abbrev == -1)
|
if (filter.abbrev == -1)
|
||||||
|
@ -323,11 +323,11 @@ test_expect_success 'git branch --list -v with --abbrev' '
|
|||||||
|
|
||||||
test_expect_success 'git branch --column' '
|
test_expect_success 'git branch --column' '
|
||||||
COLUMNS=81 git branch --column=column >actual &&
|
COLUMNS=81 git branch --column=column >actual &&
|
||||||
cat >expected <<\EOF &&
|
cat >expect <<\EOF &&
|
||||||
a/b/c bam foo l * master mb o/o q
|
a/b/c bam foo l * master mb o/o q
|
||||||
abc bar j/k m/m master2 n o/p r
|
abc bar j/k m/m master2 n o/p r
|
||||||
EOF
|
EOF
|
||||||
test_cmp expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'git branch --column with an extremely long branch name' '
|
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' '
|
|||||||
test_when_finished "git branch -d $long" &&
|
test_when_finished "git branch -d $long" &&
|
||||||
git branch $long &&
|
git branch $long &&
|
||||||
COLUMNS=80 git branch --column=column >actual &&
|
COLUMNS=80 git branch --column=column >actual &&
|
||||||
cat >expected <<EOF &&
|
cat >expect <<EOF &&
|
||||||
a/b/c
|
a/b/c
|
||||||
abc
|
abc
|
||||||
bam
|
bam
|
||||||
@ -355,7 +355,7 @@ test_expect_success 'git branch --column with an extremely long branch name' '
|
|||||||
r
|
r
|
||||||
$long
|
$long
|
||||||
EOF
|
EOF
|
||||||
test_cmp expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'git branch with column.*' '
|
test_expect_success 'git branch with column.*' '
|
||||||
@ -364,11 +364,11 @@ test_expect_success 'git branch with column.*' '
|
|||||||
COLUMNS=80 git branch >actual &&
|
COLUMNS=80 git branch >actual &&
|
||||||
git config --unset column.branch &&
|
git config --unset column.branch &&
|
||||||
git config --unset column.ui &&
|
git config --unset column.ui &&
|
||||||
cat >expected <<\EOF &&
|
cat >expect <<\EOF &&
|
||||||
a/b/c bam foo l * master mb o/o q
|
a/b/c bam foo l * master mb o/o q
|
||||||
abc bar j/k m/m master2 n o/p r
|
abc bar j/k m/m master2 n o/p r
|
||||||
EOF
|
EOF
|
||||||
test_cmp expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'git branch --column -v should fail' '
|
test_expect_success 'git branch --column -v should fail' '
|
||||||
@ -379,7 +379,7 @@ test_expect_success 'git branch -v with column.ui ignored' '
|
|||||||
git config column.ui column &&
|
git config column.ui column &&
|
||||||
COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
|
COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
|
||||||
git config --unset column.ui &&
|
git config --unset column.ui &&
|
||||||
cat >expected <<\EOF &&
|
cat >expect <<\EOF &&
|
||||||
a/b/c
|
a/b/c
|
||||||
abc
|
abc
|
||||||
bam
|
bam
|
||||||
@ -397,7 +397,7 @@ test_expect_success 'git branch -v with column.ui ignored' '
|
|||||||
q
|
q
|
||||||
r
|
r
|
||||||
EOF
|
EOF
|
||||||
test_cmp expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
mv .git/config .git/config-saved
|
mv .git/config .git/config-saved
|
||||||
@ -835,32 +835,42 @@ test_expect_success 'branch from tag w/--track causes failure' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to fails on multiple branches' '
|
test_expect_success '--set-upstream-to fails on multiple branches' '
|
||||||
test_must_fail git branch --set-upstream-to master a b c
|
echo "fatal: too many arguments to set new upstream" >expect &&
|
||||||
|
test_must_fail git branch --set-upstream-to master a b c 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to fails on detached HEAD' '
|
test_expect_success '--set-upstream-to fails on detached HEAD' '
|
||||||
git checkout HEAD^{} &&
|
git checkout HEAD^{} &&
|
||||||
test_must_fail git branch --set-upstream-to master &&
|
test_when_finished git checkout - &&
|
||||||
git checkout -
|
echo "fatal: could not set upstream of HEAD to master when it does not point to any branch." >expect &&
|
||||||
|
test_must_fail git branch --set-upstream-to master 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to fails on a missing dst branch' '
|
test_expect_success '--set-upstream-to fails on a missing dst branch' '
|
||||||
test_must_fail git branch --set-upstream-to master does-not-exist
|
echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect &&
|
||||||
|
test_must_fail git branch --set-upstream-to master does-not-exist 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to fails on a missing src branch' '
|
test_expect_success '--set-upstream-to fails on a missing src branch' '
|
||||||
test_must_fail git branch --set-upstream-to does-not-exist master
|
test_must_fail git branch --set-upstream-to does-not-exist master 2>err &&
|
||||||
|
test_i18ngrep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to fails on a non-ref' '
|
test_expect_success '--set-upstream-to fails on a non-ref' '
|
||||||
test_must_fail git branch --set-upstream-to HEAD^{}
|
echo "fatal: Cannot setup tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch." >expect &&
|
||||||
|
test_must_fail git branch --set-upstream-to HEAD^{} 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to fails on locked config' '
|
test_expect_success '--set-upstream-to fails on locked config' '
|
||||||
test_when_finished "rm -f .git/config.lock" &&
|
test_when_finished "rm -f .git/config.lock" &&
|
||||||
>.git/config.lock &&
|
>.git/config.lock &&
|
||||||
git branch locked &&
|
git branch locked &&
|
||||||
test_must_fail git branch --set-upstream-to locked
|
test_must_fail git branch --set-upstream-to locked 2>err &&
|
||||||
|
test_i18ngrep "could not lock config file .git/config: File exists" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'use --set-upstream-to modify HEAD' '
|
test_expect_success 'use --set-upstream-to modify HEAD' '
|
||||||
@ -881,14 +891,17 @@ test_expect_success 'use --set-upstream-to modify a particular branch' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--unset-upstream should fail if given a non-existent branch' '
|
test_expect_success '--unset-upstream should fail if given a non-existent branch' '
|
||||||
test_must_fail git branch --unset-upstream i-dont-exist
|
echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect &&
|
||||||
|
test_must_fail git branch --unset-upstream i-dont-exist 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--unset-upstream should fail if config is locked' '
|
test_expect_success '--unset-upstream should fail if config is locked' '
|
||||||
test_when_finished "rm -f .git/config.lock" &&
|
test_when_finished "rm -f .git/config.lock" &&
|
||||||
git branch --set-upstream-to locked &&
|
git branch --set-upstream-to locked &&
|
||||||
>.git/config.lock &&
|
>.git/config.lock &&
|
||||||
test_must_fail git branch --unset-upstream
|
test_must_fail git branch --unset-upstream 2>err &&
|
||||||
|
test_i18ngrep "could not lock config file .git/config: File exists" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'test --unset-upstream on HEAD' '
|
test_expect_success 'test --unset-upstream on HEAD' '
|
||||||
@ -900,17 +913,23 @@ test_expect_success 'test --unset-upstream on HEAD' '
|
|||||||
test_must_fail git config branch.master.remote &&
|
test_must_fail git config branch.master.remote &&
|
||||||
test_must_fail git config branch.master.merge &&
|
test_must_fail git config branch.master.merge &&
|
||||||
# fail for a branch without upstream set
|
# fail for a branch without upstream set
|
||||||
test_must_fail git branch --unset-upstream
|
echo "fatal: Branch '"'"'master'"'"' has no upstream information" >expect &&
|
||||||
|
test_must_fail git branch --unset-upstream 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--unset-upstream should fail on multiple branches' '
|
test_expect_success '--unset-upstream should fail on multiple branches' '
|
||||||
test_must_fail git branch --unset-upstream a b c
|
echo "fatal: too many arguments to unset upstream" >expect &&
|
||||||
|
test_must_fail git branch --unset-upstream a b c 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--unset-upstream should fail on detached HEAD' '
|
test_expect_success '--unset-upstream should fail on detached HEAD' '
|
||||||
git checkout HEAD^{} &&
|
git checkout HEAD^{} &&
|
||||||
test_must_fail git branch --unset-upstream &&
|
test_when_finished git checkout - &&
|
||||||
git checkout -
|
echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect &&
|
||||||
|
test_must_fail git branch --unset-upstream 2>err &&
|
||||||
|
test_i18ncmp expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'test --unset-upstream on a particular branch' '
|
test_expect_success 'test --unset-upstream on a particular branch' '
|
||||||
@ -922,17 +941,17 @@ test_expect_success 'test --unset-upstream on a particular branch' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'disabled option --set-upstream fails' '
|
test_expect_success 'disabled option --set-upstream fails' '
|
||||||
test_must_fail git branch --set-upstream origin/master
|
test_must_fail git branch --set-upstream origin/master
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
|
test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
|
||||||
git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
|
git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
|
||||||
cat >expected <<-\EOF &&
|
cat >expect <<-\EOF &&
|
||||||
warning: Not setting branch my13 as its own upstream.
|
warning: Not setting branch my13 as its own upstream.
|
||||||
EOF
|
EOF
|
||||||
test_expect_code 1 git config branch.my13.remote &&
|
test_expect_code 1 git config branch.my13.remote &&
|
||||||
test_expect_code 1 git config branch.my13.merge &&
|
test_expect_code 1 git config branch.my13.merge &&
|
||||||
test_i18ncmp expected actual
|
test_i18ncmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
# Keep this test last, as it changes the current branch
|
# Keep this test last, as it changes the current branch
|
||||||
|
Reference in New Issue
Block a user