aboutsummaryrefslogtreecommitdiff
path: root/builtin-branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-03-08 13:59:54 -0800
committerJunio C Hamano <junkio@cox.net>2007-03-10 23:41:58 -0800
commit45994a1e33398e55426268fcd5d4ab3143497e29 (patch)
treed067d8436e0ad661d223713d68eb3fb7c24c5419 /builtin-branch.c
parent0746d19a823aa12239df9d32db6fa6795d8c8539 (diff)
downloadgit-45994a1e33398e55426268fcd5d4ab3143497e29.tar.gz
git-45994a1e33398e55426268fcd5d4ab3143497e29.tar.xz
Fix broken create_branch() in builtin-branch.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-branch.c')
-rw-r--r--builtin-branch.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/builtin-branch.c b/builtin-branch.c
index e161e0097..42b1ff129 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -410,7 +410,6 @@ static void set_branch_defaults(const char *name, const char *real_ref)
}
static void create_branch(const char *name, const char *start_name,
- unsigned char *start_sha1,
int force, int reflog, int track)
{
struct ref_lock *lock;
@@ -431,15 +430,22 @@ static void create_branch(const char *name, const char *start_name,
forcing = 1;
}
- if (start_sha1) {
- /* detached HEAD */
- hashcpy(sha1, start_sha1);
+ real_ref = NULL;
+ if (get_sha1(start_name, sha1))
+ die("Not a valid object name: '%s'.", start_name);
+
+ switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
+ case 0:
+ /* Not branching from any existing branch */
real_ref = NULL;
- }
- else if (dwim_ref(start_name, strlen(start_name), sha1, &real_ref) > 1)
+ break;
+ case 1:
+ /* Unique completion -- good */
+ break;
+ default:
die("Ambiguous object name: '%s'.", start_name);
- else if (real_ref == NULL)
- die("Not a valid object name: '%s'.", start_name);
+ break;
+ }
if ((commit = lookup_commit_reference(sha1)) == NULL)
die("Not a valid branch point: '%s'.", start_name);
@@ -620,12 +626,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
rename_branch(head, argv[i], force_rename);
else if (rename && (i == argc - 2))
rename_branch(argv[i], argv[i + 1], force_rename);
- else if (i == argc - 1)
- create_branch(argv[i], head, head_sha1, force_create, reflog,
- track);
- else if (i == argc - 2)
- create_branch(argv[i], argv[i+1], NULL, force_create, reflog,
- track);
+ else if (i == argc - 1 || i == argc - 2)
+ create_branch(argv[i], (i == argc - 2) ? argv[i+1] : head,
+ force_create, reflog, track);
else
usage(builtin_branch_usage);