diff options
author | Rubén Justo <rjusto@gmail.com> | 2022-10-08 03:39:43 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-10-08 06:59:41 +0300 |
commit | bcfc82bd48f518c8939090748516ad21bb079720 (patch) | |
tree | d806e4de109e6fd0d32ac41755a1b410a9242ed4 /t/t3202-show-branch.sh | |
parent | bcd6bc478adc4951d57ec597c44b12ee74bc88fb (diff) |
branch: description for non-existent branch errors
When the repository does not yet have commits, some errors describe that
there is no branch:
$ git init -b first
$ git branch --edit-description first
error: No branch named 'first'.
$ git branch --set-upstream-to=upstream
fatal: branch 'first' does not exist
$ git branch -c second
error: refname refs/heads/first not found
fatal: Branch copy failed
That "first" branch is unborn but to say it doesn't exists is confusing.
Options "-c" (copy) and "-m" (rename) show the same error when the
origin branch doesn't exists:
$ git branch -c non-existent-branch second
error: refname refs/heads/non-existent-branch not found
fatal: Branch copy failed
$ git branch -m non-existent-branch second
error: refname refs/heads/non-existent-branch not found
fatal: Branch rename failed
Note that "--edit-description" without an explicit argument is already
considering the _empty repository_ circumstance in its error. Also note
that "-m" on the initial branch it is an allowed operation.
Make the error descriptions for those branch operations with unborn or
non-existent branches, more informative.
This is the result of the change:
$ git init -b first
$ git branch --edit-description first
error: No commit on branch 'first' yet.
$ git branch --set-upstream-to=upstream
fatal: No commit on branch 'first' yet.
$ git branch -c second
fatal: No commit on branch 'first' yet.
$ git branch [-c/-m] non-existent-branch second
fatal: No branch named 'non-existent-branch'.
Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3202-show-branch.sh')
-rwxr-xr-x | t/t3202-show-branch.sh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh index f2b9199007..ea7cfd1951 100755 --- a/t/t3202-show-branch.sh +++ b/t/t3202-show-branch.sh @@ -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 |