branch: reject -D/-d without branch name
PATCH 1/1 branch: reject -D/-d without branch name
--- builtin/branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/branch.c +1 -1
@@ -837,7 +837,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) colopts =0 ; } -if (delete) +if (delete && argc)return delete_branches (argc, argv, delete >1 , kinds, quiet);else if (list) { int ret = print_ref_list(kinds, detached, verbose, abbrev,
Signature · 1 line
1.8.1.1.380.g782aa97
PATCH v2 1/3 branch: reject -D/-d without branch name
--- builtin/branch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
builtin/branch.c +4 -2
@@ -837,9 +837,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix) colopts =0 ; } -if (delete) +if (delete) { +if (!argc) +die (_ ("branch name required" ));return delete_branches (argc, argv, delete >1 , kinds, quiet); -else if (list) { + }else if (list) {int ret =print_ref_list (kinds, detached, verbose, abbrev, with_commit, argv);print_columns (&output, colopts,NULL );
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v2 2/3 branch: give a more helpful message on redundant arguments
While at there, do not stop user from editing a branch description when the unrelated HEAD is detached.
--- builtin/branch.c | 12 ++++++------ t/t3200-branch.sh | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-)
builtin/branch.c +6 -6
@@ -852,14 +852,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)const char *branch_name;struct strbuf branch_ref =STRBUF_INIT ; -if (detached) -die ("Cannot give description to detached HEAD" ); -if (!argc) +if (!argc) { +if (detached) +die ("Cannot give description to detached HEAD" ); branch_name = head; -else if (argc ==1 ) + }else if (argc ==1 ) branch_name = argv[0 ];else -usage_with_options (builtin_branch_usage, options); +die (_ ("cannot edit description of more than one branch" ));strbuf_addf (&branch_ref,"refs/heads/%s" , branch_name);if (!ref_exists (branch_ref.buf)) {
@@ -881,7 +881,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)else if (argc ==2 )rename_branch (argv[0 ], argv[1 ], rename >1 );else -usage_with_options (builtin_branch_usage, options); +die (_ ("too many branches for a rename operation" )); }else if (new_upstream) {struct branch *branch =branch_get (argv[0 ]);
t/t3200-branch.sh +2 -2
@@ -73,8 +73,8 @@ test_expect_success \ test_expect_success \ 'git branch -m dumps usage' \ - 'test_expect_code 129 git branch -m 2>err && - test_i18ngrep "[Uu]sage: git branch" err' + 'test_expect_code 128 git branch -m 2>err && + test_i18ngrep "too many branches for a rename operation" err' test_expect_success \ 'git branch -m m m/m should work' \
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v2 3/3 branch: mark more strings for translation
In reply to Nguyễn Thái Ngọc Duy--- builtin/branch.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
builtin/branch.c +6 -5
@@ -466,7 +466,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item, int verbose, int abbrev) {struct strbuf subject =STRBUF_INIT , stat =STRBUF_INIT ; -const char *sub =" **** invalid ref ****" ; +const char *sub =_ (" **** invalid ref ****" );struct commit *commit = item->commit;if (commit && !parse_commit (commit)) {
@@ -590,7 +590,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, strustruct commit *filter; filter =lookup_commit_reference_gently (merge_filter_ref,0 );if (!filter) -die ("object '%s' does not point to a commit" , +die (_ ("object '%s' does not point to a commit" ),sha1_to_hex (merge_filter_ref)); filter->object.flags |=UNINTERESTING ;
@@ -854,7 +854,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (!argc) {if (detached) -die ("Cannot give description to detached HEAD" ); +die (_ ("Cannot give description to detached HEAD" )); branch_name = head; }else if (argc ==1 ) branch_name = argv[0 ];
@@ -866,10 +866,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)strbuf_release (&branch_ref);if (!argc) -return error ("No commit on branch '%s' yet." , +return error (_ ("No commit on branch '%s' yet." ), branch_name);else -return error ("No such branch '%s'." , branch_name); +return error (_ ("No branch named '%s'." ), + branch_name); }strbuf_release (&branch_ref);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
builtin/branch.c int cmd_branch(int argc, const char **argv, const char *prefix) · line 843
Quoted 13 lines · Nguyễn Thái Ngọc Duy
builtin/branch.c +1
-1@@ -837,7 +837,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) colopts =0 ; } -if (delete) +if (delete && argc)return delete_branches (argc, argv, delete >1 , kinds, quiet);else if (list) { int ret = print_ref_list(kinds, detached, verbose, abbrev,
Shouldn't this error out with a clean error message ("branch name expected" or so)?
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 10 lines · Matthieu Moy
Quoted 8 lines · Nguyễn Thái Ngọc Duy
builtin/branch.c +0
-0@@ -837,7 +837,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) colopts =0 ; }
Quoted 8 lines
builtin/branch.c int cmd_branch(int argc, const char **argv, const char *prefix) · line 843
Quoted 5 lines
builtin/branch.c +1
-1-if (delete) +if (delete && argc)return delete_branches (argc, argv, delete >1 , kinds, quiet);else if (list) { int ret = print_ref_list(kinds, detached, verbose, abbrev,Shouldn't this error out with a clean error message ("branch name expected" or so)?
Yeah. But on the other hand, this command seems to prefer to print help usage when incorrect number of arguments is given (checkout blocks "if (edit_description)" and "if (rename)" in cmd_branch). Should those be fixed too?
Signature · 1 line
Duy
Quoted 3 lines · Nguyễn Thái Ngọc Duy
--- builtin/branch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Forgot to sign-off?
Is this a real problem?
I do not see it particularly wrong to succeed after deleting 0 or more given branch names.
Quoted 19 lines
builtin/branch.c +4
-2@@ -837,9 +837,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix) colopts =0 ; } -if (delete) +if (delete) { +if (!argc) +die (_ ("branch name required" ));return delete_branches (argc, argv, delete >1 , kinds, quiet); -else if (list) { + }else if (list) {int ret =print_ref_list (kinds, detached, verbose, abbrev, with_commit, argv);print_columns (&output, colopts,NULL );
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · Nguyễn Thái Ngọc Duy
--- builtin/branch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)Forgot to sign-off?
Yes
Quoted 1 line
Is this a real problem?
Yes. My thoughts yesterday when I happened to type "git branch -D":
"Wait, I just entered a delete command without a branch name. It did not report anything, which in UNIX world usually means successful operation. _What_ did it delete??"
I knew this code so I just went check. If I did not know, I might as well list all branches I had and see if something was missing. A short message would have saved me the trouble.
Quoted 2 lines
I do not see it particularly wrong to succeed after deleting 0 or more given branch names.
Signature · 1 line
Duy
Re: [PATCH v2 2/3] branch: give a more helpful message on redundant arguments
In reply to Nguyễn Thái Ngọc Duybuiltin/branch.c int cmd_branch(int argc, const char **argv, const char *prefix) · line 857
Quoted 12 lines · Nguyễn Thái Ngọc Duy
builtin/branch.c +3
-3@@ -852,14 +852,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)const char *branch_name;struct strbuf branch_ref =STRBUF_INIT ; -if (detached) -die ("Cannot give description to detached HEAD" ); -if (!argc) +if (!argc) { +if (detached) +die ("Cannot give description to detached HEAD" );
Good catch. Shouldn't this bugfix be a separate patch, so it can also be included in maint?
Re: [PATCH v2 3/3] branch: mark more strings for translation
In reply to Nguyễn Thái Ngọc Duybuiltin/branch.c static void add_verbose_info(struct strbuf *out, struct ref_item *item, · line 469
Quoted 8 lines · Nguyễn Thái Ngọc Duy
builtin/branch.c +1
-1@@ -466,7 +466,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item, int verbose, int abbrev) {struct strbuf subject =STRBUF_INIT , stat =STRBUF_INIT ; -const char *sub =" **** invalid ref ****" ; +const char *sub =_ (" **** invalid ref ****" );
This worried me for a second --- is it an actual message that gets emitted, a placeholder used only in code, or some combination of the two?
Luckily it really is just a message (or rather, a value for the commit message column in the " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" message).
For what it's worth, assuming this passes tests,
PATCH v3 1/4 branch: no detached HEAD check when editing another branch's description
In reply to Nguyễn Thái Ngọc Duy---
Split out from v3's 2/3 as Jonathan suggested.
builtin/branch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/branch.c +4 -4
@@ -850,11 +850,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)const char *branch_name;struct strbuf branch_ref =STRBUF_INIT ; -if (detached) -die ("Cannot give description to detached HEAD" ); -if (!argc) +if (!argc) { +if (detached) +die ("Cannot give description to detached HEAD" ); branch_name = head; -else if (argc ==1 ) + }else if (argc ==1 ) branch_name = argv[0 ];else usage_with_options (builtin_branch_usage, options);
Signature · 1 line
1.8.1.1.459.g5970e58
PATCH v3 2/4 branch: reject -D/-d without branch name
--- builtin/branch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
builtin/branch.c +4 -2
@@ -837,9 +837,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix) colopts =0 ; } -if (delete) +if (delete) { +if (!argc) +die (_ ("branch name required" ));return delete_branches (argc, argv, delete >1 , kinds, quiet); -else if (list) { + }else if (list) {int ret =print_ref_list (kinds, detached, verbose, abbrev, with_commit, argv);print_columns (&output, colopts,NULL );
Signature · 1 line
1.8.1.1.459.g5970e58
PATCH v3 3/4 branch: give a more helpful message on redundant arguments
In reply to Nguyễn Thái Ngọc Duy--- builtin/branch.c | 4 ++-- t/t3200-branch.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
builtin/branch.c +2 -2
@@ -859,7 +859,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) }else if (argc ==1 ) branch_name = argv[0 ];else -usage_with_options (builtin_branch_usage, options); +die (_ ("cannot edit description of more than one branch" ));strbuf_addf (&branch_ref,"refs/heads/%s" , branch_name);if (!ref_exists (branch_ref.buf)) {
@@ -881,7 +881,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)else if (argc ==2 )rename_branch (argv[0 ], argv[1 ], rename >1 );else -usage_with_options (builtin_branch_usage, options); +die (_ ("too many branches for a rename operation" )); }else if (new_upstream) {struct branch *branch =branch_get (argv[0 ]);
t/t3200-branch.sh +2 -2
@@ -73,8 +73,8 @@ test_expect_success \ test_expect_success \ 'git branch -m dumps usage' \ - 'test_expect_code 129 git branch -m 2>err && - test_i18ngrep "[Uu]sage: git branch" err' + 'test_expect_code 128 git branch -m 2>err && + test_i18ngrep "too many branches for a rename operation" err' test_expect_success \ 'git branch -m m m/m should work' \
Signature · 1 line
1.8.1.1.459.g5970e58
PATCH v3 4/4 branch: mark more strings for translation
In reply to Nguyễn Thái Ngọc Duy---
Quoted 1 line · Jonathan Nieder
For what it's worth, assuming this passes tests,
It passes the tests. Although I doubt the tests are written to catch this.
builtin/branch.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
builtin/branch.c +6 -5
@@ -466,7 +466,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item, int verbose, int abbrev) {struct strbuf subject =STRBUF_INIT , stat =STRBUF_INIT ; -const char *sub =" **** invalid ref ****" ; +const char *sub =_ (" **** invalid ref ****" );struct commit *commit = item->commit;if (commit && !parse_commit (commit)) {
@@ -590,7 +590,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, strustruct commit *filter; filter =lookup_commit_reference_gently (merge_filter_ref,0 );if (!filter) -die ("object '%s' does not point to a commit" , +die (_ ("object '%s' does not point to a commit" ),sha1_to_hex (merge_filter_ref)); filter->object.flags |=UNINTERESTING ;
@@ -854,7 +854,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (!argc) {if (detached) -die ("Cannot give description to detached HEAD" ); +die (_ ("Cannot give description to detached HEAD" )); branch_name = head; }else if (argc ==1 ) branch_name = argv[0 ];
@@ -866,10 +866,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)strbuf_release (&branch_ref);if (!argc) -return error ("No commit on branch '%s' yet." , +return error (_ ("No commit on branch '%s' yet." ), branch_name);else -return error ("No such branch '%s'." , branch_name); +return error (_ ("No branch named '%s'." ), + branch_name); }strbuf_release (&branch_ref);
Signature · 1 line
1.8.1.1.459.g5970e58