diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-02-13 11:42:07 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-02-13 11:42:07 -0800 |
commit | 8eb865ba8a24aad5380a23fc1e331aba2f7c5bbb (patch) | |
tree | c995cd1c09a8faed705a3fcf5f77a5b47a5533f2 /builtin | |
parent | Merge branch 'jn/rpm-spec' into maint (diff) | |
parent | branch --edit-description: protect against mistyped branch name (diff) | |
download | tgif-8eb865ba8a24aad5380a23fc1e331aba2f7c5bbb.tar.xz |
Merge branch 'jc/branch-desc-typoavoidance' into maint
* jc/branch-desc-typoavoidance:
branch --edit-description: protect against mistyped branch name
tests: add write_script helper function
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/branch.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 7095718c13..cb17bc3675 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -768,6 +768,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix) with_commit, argv); else if (edit_description) { const char *branch_name; + struct strbuf branch_ref = STRBUF_INIT; + if (detached) die("Cannot give description to detached HEAD"); if (!argc) @@ -776,6 +778,19 @@ int cmd_branch(int argc, const char **argv, const char *prefix) branch_name = argv[0]; else usage_with_options(builtin_branch_usage, options); + + strbuf_addf(&branch_ref, "refs/heads/%s", branch_name); + if (!ref_exists(branch_ref.buf)) { + strbuf_release(&branch_ref); + + if (!argc) + return error("No commit on branch '%s' yet.", + branch_name); + else + return error("No such branch '%s'.", branch_name); + } + strbuf_release(&branch_ref); + if (edit_branch_description(branch_name)) return 1; } else if (rename) { |