mirror of
https://github.com/git/git
synced 2024-08-25 10:45:59 +00:00
Merge branch 'rj/branch-edit-desc-unborn'
"git branch --edit-description" on an unborh branch misleadingly said that no such branch exists, which has been corrected. * rj/branch-edit-desc-unborn: branch: description for non-existent branch errors
This commit is contained in:
commit
4050354b14
|
@ -538,6 +538,13 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
|
|||
die(_("Invalid branch name: '%s'"), oldname);
|
||||
}
|
||||
|
||||
if ((copy || strcmp(head, oldname)) && !ref_exists(oldref.buf)) {
|
||||
if (copy && !strcmp(head, oldname))
|
||||
die(_("No commit on branch '%s' yet."), oldname);
|
||||
else
|
||||
die(_("No branch named '%s'."), oldname);
|
||||
}
|
||||
|
||||
/*
|
||||
* A command like "git branch -M currentbranch currentbranch" cannot
|
||||
* cause the worktree to become inconsistent with HEAD, so allow it.
|
||||
|
@ -807,7 +814,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
|||
if (!ref_exists(branch_ref.buf)) {
|
||||
strbuf_release(&branch_ref);
|
||||
|
||||
if (!argc)
|
||||
if (!argc || !strcmp(head, branch_name))
|
||||
return error(_("No commit on branch '%s' yet."),
|
||||
branch_name);
|
||||
else
|
||||
|
@ -850,8 +857,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
|||
die(_("no such branch '%s'"), argv[0]);
|
||||
}
|
||||
|
||||
if (!ref_exists(branch->refname))
|
||||
if (!ref_exists(branch->refname)) {
|
||||
if (!argc || !strcmp(head, branch->name))
|
||||
die(_("No commit on branch '%s' yet."), branch->name);
|
||||
die(_("branch '%s' does not exist"), branch->name);
|
||||
}
|
||||
|
||||
dwim_and_setup_tracking(the_repository, branch->name,
|
||||
new_upstream, BRANCH_TRACK_OVERRIDE,
|
||||
|
|
|
@ -7,6 +7,28 @@ test_description='test show-branch'
|
|||
# arbitrary reference time: 2009-08-30 19:20:00
|
||||
GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW
|
||||
|
||||
test_expect_success 'error descriptions on empty repository' '
|
||||
current=$(git branch --show-current) &&
|
||||
cat >expect <<-EOF &&
|
||||
error: No commit on branch '\''$current'\'' yet.
|
||||
EOF
|
||||
test_must_fail git branch --edit-description 2>actual &&
|
||||
test_cmp expect actual &&
|
||||
test_must_fail git branch --edit-description $current 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'fatal descriptions on empty repository' '
|
||||
current=$(git branch --show-current) &&
|
||||
cat >expect <<-EOF &&
|
||||
fatal: No commit on branch '\''$current'\'' yet.
|
||||
EOF
|
||||
test_must_fail git branch --set-upstream-to=non-existent 2>actual &&
|
||||
test_cmp expect actual &&
|
||||
test_must_fail git branch -c new-branch 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'setup' '
|
||||
test_commit initial &&
|
||||
for i in $(test_seq 1 10)
|
||||
|
@ -175,4 +197,28 @@ done <<\EOF
|
|||
--reflog --current
|
||||
EOF
|
||||
|
||||
test_expect_success 'error descriptions on non-existent branch' '
|
||||
cat >expect <<-EOF &&
|
||||
error: No branch named '\''non-existent'\'.'
|
||||
EOF
|
||||
test_must_fail git branch --edit-description non-existent 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'fatal descriptions on non-existent branch' '
|
||||
cat >expect <<-EOF &&
|
||||
fatal: branch '\''non-existent'\'' does not exist
|
||||
EOF
|
||||
test_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
fatal: No branch named '\''non-existent'\''.
|
||||
EOF
|
||||
test_must_fail git branch -c non-existent new-branch 2>actual &&
|
||||
test_cmp expect actual &&
|
||||
test_must_fail git branch -m non-existent new-branch 2>actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue