From 5f856dd47dacb30fb9f605b4b7e1fa577ada7d26 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 19 Jan 2007 11:51:29 -0800 Subject: fix reflog entries for "git-branch" Even when -l is not given from the command line, the repository may have the configuration variable core.logallrefupdates set, or an old-timer might have done ": >.git/logs/refs/heads/new" before running "git branch new". In these cases, the code gave an uninitialized msg[] from the stack to be written out as the reflog message. This also passes a different message when '-f' option is used. Saying "git branch -f branch some-commit" is a moral equilvalent of doing "git-reset some-commit" while on the branch. Signed-off-by: Junio C Hamano --- builtin-branch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'builtin-branch.c') diff --git a/builtin-branch.c b/builtin-branch.c index d60690bb08..eaff54ec5f 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)); -- cgit v1.2.3 From 3dff5379bf1e3fda5e5a84ca5813b0c0cfd51be7 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sat, 3 Feb 2007 23:49:16 -0500 Subject: Assorted typo fixes Signed-off-by: Junio C Hamano --- builtin-branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-branch.c') diff --git a/builtin-branch.c b/builtin-branch.c index eaff54ec5f..9b68d3b69f 100644 --- a/builtin-branch.c +++ b/builtin-branch.c @@ -364,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"); -- cgit v1.2.3