X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-branch.c;h=2d8d61b453ede72b8d0319cb192f9f06a024d8c0;hb=c6ec3b13b81d59272e41d5316689c65dd4cc2e63;hp=25ffa5491c62ea047e5fad78e60b8fa7e4e6a2fe;hpb=11a6ddb2c8a81815ee9d5411638487ee99770a0b;p=git.git diff --git a/builtin-branch.c b/builtin-branch.c index 25ffa5491..2d8d61b45 100644 --- a/builtin-branch.c +++ b/builtin-branch.c @@ -316,6 +316,7 @@ static void create_branch(const char *name, const char *start_name, struct commit *commit; unsigned char sha1[20]; char ref[PATH_MAX], msg[PATH_MAX + 20]; + int forcing = 0; snprintf(ref, sizeof ref, "refs/heads/%s", name); if (check_ref_format(ref)) @@ -326,6 +327,7 @@ static void create_branch(const char *name, const char *start_name, die("A branch named '%s' already exists.", name); else if (!is_bare_repository() && !strcmp(head, name)) die("Cannot force update the current branch."); + forcing = 1; } if (start_sha1) @@ -342,11 +344,15 @@ static void create_branch(const char *name, const char *start_name, if (!lock) die("Failed to lock ref for update: %s.", strerror(errno)); - if (reflog) { + if (reflog) log_all_ref_updates = 1; + + if (forcing) + snprintf(msg, sizeof msg, "branch: Reset from %s", + start_name); + else snprintf(msg, sizeof msg, "branch: Created from %s", start_name); - } if (write_ref_sha1(lock, sha1, msg) < 0) die("Failed to write ref: %s.", strerror(errno)); @@ -358,7 +364,7 @@ static void rename_branch(const char *oldname, const char *newname, int force) unsigned char sha1[20]; if (!oldname) - die("cannot rename the curren branch while not on any."); + die("cannot rename the current branch while not on any."); if (snprintf(oldref, sizeof(oldref), "refs/heads/%s", oldname) > sizeof(oldref)) die("Old branchname too long"); @@ -381,7 +387,8 @@ static void rename_branch(const char *oldname, const char *newname, int force) if (rename_ref(oldref, newref, logmsg)) die("Branch rename failed"); - if (!strcmp(oldname, head) && create_symref("HEAD", newref)) + /* no need to pass logmsg here as HEAD didn't really move */ + if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL)) die("Branch renamed to %s, but HEAD is not updated!", newname); } @@ -394,7 +401,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix) int kinds = REF_LOCAL_BRANCH; int i; - setup_ident(); git_config(git_branch_config); for (i = 1; i < argc; i++) {