Message ID | 20181016145428.2901-1-taoqy@ls-a.me (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] builtin/branch.c: remove useless branch_get | expand |
On Tue, Oct 16, 2018 at 10:54:28PM +0800, Tao Qingyun wrote: > branch_get sometimes returns current_branch, which can be NULL (e.g., if > you're on a detached HEAD). Try: > > $ git branch HEAD > fatal: no such branch 'HEAD' > > $ git branch '' > fatal: no such branch '' > > However, it seems weird that we'd check those cases here (and provide > such lousy messages). And indeed, dropping that and letting us > eventually hit create_branch() gives a much better message: > > $ git branch HEAD > fatal: 'HEAD' is not a valid branch name. > > $ git branch '' > fatal: '' is not a valid branch name. This explanation is perfect, of course. ;) I still wondered if you had another motivation hinted at in your original mail, though (some weirdness with running branch_get early). It's OK if there isn't one, but I just want to make sure we capture all of the details. Other than that question, the patch looks good to me. -Peff
> > branch_get sometimes returns current_branch, which can be NULL (e.g., if > > you're on a detached HEAD). Try: > > > > $ git branch HEAD > > fatal: no such branch 'HEAD' > > > > $ git branch '' > > fatal: no such branch '' > > > > However, it seems weird that we'd check those cases here (and provide > > such lousy messages). And indeed, dropping that and letting us > > eventually hit create_branch() gives a much better message: > > > > $ git branch HEAD > > fatal: 'HEAD' is not a valid branch name. > > > > $ git branch '' > > fatal: '' is not a valid branch name. > > This explanation is perfect, of course. ;) > > I still wondered if you had another motivation hinted at in your > original mail, though (some weirdness with running branch_get early). > It's OK if there isn't one, but I just want to make sure we capture all > of the details. > Yes, this explanation is perfect. ;) > Other than that question, the patch looks good to me. > > -Peff
diff --git a/builtin/branch.c b/builtin/branch.c index c396c41533..2367703034 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -809,11 +809,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix) git_config_set_multivar(buf.buf, NULL, NULL, 1); strbuf_release(&buf); } else if (argc > 0 && argc <= 2) { - struct branch *branch = branch_get(argv[0]); - - if (!branch) - die(_("no such branch '%s'"), argv[0]); - if (filter.kind != FILTER_REFS_BRANCHES) die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
branch_get sometimes returns current_branch, which can be NULL (e.g., if you're on a detached HEAD). Try: $ git branch HEAD fatal: no such branch 'HEAD' $ git branch '' fatal: no such branch '' However, it seems weird that we'd check those cases here (and provide such lousy messages). And indeed, dropping that and letting us eventually hit create_branch() gives a much better message: $ git branch HEAD fatal: 'HEAD' is not a valid branch name. $ git branch '' fatal: '' is not a valid branch name. Signed-off-by: Tao Qingyun <taoqy@ls-a.me> --- builtin/branch.c | 5 ----- 1 file changed, 5 deletions(-)