aboutsummaryrefslogtreecommitdiff
path: root/builtin-checkout.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-03-21 14:35:51 -0700
committerJunio C Hamano <gitster@pobox.com>2009-03-22 23:52:11 -0700
commita2fab531bbb00ff64335906e22854365be2eb5c7 (patch)
tree3ae5efaa819454c41ece9566e0b38df7fadebd94 /builtin-checkout.c
parent03d3aada5a2a68a7acdb6286fd72155f01626e41 (diff)
downloadgit-a2fab531bbb00ff64335906e22854365be2eb5c7.tar.gz
git-a2fab531bbb00ff64335906e22854365be2eb5c7.tar.xz
strbuf_check_branch_ref(): a helper to check a refname for a branch
This allows a common calling sequence strbuf_branchname(&ref, name); strbuf_splice(&ref, 0, 0, "refs/heads/", 11); if (check_ref_format(ref.buf)) die(...); to be refactored into if (strbuf_check_branch_ref(&ref, name)) die(...); Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r--builtin-checkout.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index b2680466d..66df0c072 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -733,12 +733,11 @@ no_reference:
if (opts.new_branch) {
struct strbuf buf = STRBUF_INIT;
- strbuf_addstr(&buf, "refs/heads/");
- strbuf_addstr(&buf, opts.new_branch);
+ if (strbuf_check_branch_ref(&buf, opts.new_branch))
+ die("git checkout: we do not like '%s' as a branch name.",
+ opts.new_branch);
if (!get_sha1(buf.buf, rev))
die("git checkout: branch %s already exists", opts.new_branch);
- if (check_ref_format(buf.buf))
- die("git checkout: we do not like '%s' as a branch name.", opts.new_branch);
strbuf_release(&buf);
}