diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-02-10 14:07:58 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-02-10 14:07:58 -0800 |
commit | d88698ec0b4b91e61b0fe3e00d7451abcdf4cd44 (patch) | |
tree | cefb3bd2ea1ca666a7be7c80ad052785fd8d2c71 /builtin | |
parent | e684e89ef00e229c9fc6e7d53264fb03d4732d4c (diff) | |
parent | c2d17ba3db0d2b14daf04e69a8c5ec73b023c1fe (diff) | |
download | git-d88698ec0b4b91e61b0fe3e00d7451abcdf4cd44.tar.gz git-d88698ec0b4b91e61b0fe3e00d7451abcdf4cd44.tar.xz |
Merge branch 'jc/branch-desc-typoavoidance'
* jc/branch-desc-typoavoidance:
branch --edit-description: protect against mistyped branch name
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 7095718c1..cb17bc367 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) { |