From: Kyle Meyer <kyle@kyleam.com>
To: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Cc: Kyle Meyer <kyle@kyleam.com>, git@vger.kernel.org
Subject: [PATCH 3/3] rename_ref: replace empty deletion message in HEAD's log
Date: Thu, 16 Feb 2017 22:58:00 -0500 [thread overview]
Message-ID: <20170217035800.13214-4-kyle@kyleam.com> (raw)
In-Reply-To: <20170217035800.13214-1-kyle@kyleam.com>
When the current branch is renamed, the deletion of the old ref is
recorded in HEAD's log with an empty message. Now that delete_refs()
accepts a reflog message, provide a more descriptive message. This
message will not be included in the reflog of the renamed branch, but
its log already covers the renaming event with a message of "Branch:
renamed ...".
Signed-off-by: Kyle Meyer <kyle@kyleam.com>
---
refs/files-backend.c | 8 +++++++-
t/t3200-branch.sh | 4 ++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index ffa75d816..bb5df7ee6 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2598,6 +2598,7 @@ static int files_rename_ref(struct ref_store *ref_store,
struct stat loginfo;
int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
struct strbuf err = STRBUF_INIT;
+ struct strbuf logmsg_del = STRBUF_INIT;
if (log && S_ISLNK(loginfo.st_mode))
return error("reflog for %s is a symlink", oldrefname);
@@ -2616,10 +2617,15 @@ static int files_rename_ref(struct ref_store *ref_store,
return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
oldrefname, strerror(errno));
- if (delete_ref(oldrefname, orig_sha1, REF_NODEREF, NULL)) {
+ strbuf_addf(&logmsg_del, "Deleted %s", oldrefname);
+
+ if (delete_ref(oldrefname, orig_sha1, REF_NODEREF, logmsg_del.buf)) {
error("unable to delete old %s", oldrefname);
+ strbuf_release(&logmsg_del);
goto rollback;
}
+ strbuf_release(&logmsg_del);
+
/*
* Since we are doing a shallow lookup, sha1 is not the
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 8a833f354..4af7cd2b7 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -139,6 +139,10 @@ test_expect_success 'git branch -M baz bam should succeed when baz is checked ou
test $(git rev-parse --abbrev-ref HEAD) = bam
'
+test_expect_success 'git branch -M baz bam should add entry to .git/logs/HEAD' '
+ grep "Deleted refs/heads/baz$" .git/logs/HEAD >/dev/null
+'
+
test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
git checkout master &&
git worktree add -b baz bazdir &&
--
2.11.1
next prev parent reply other threads:[~2017-02-17 3:59 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-16 23:17 HEAD's reflog entry for a renamed branch Kyle Meyer
2017-01-26 21:12 ` Jeff King
2017-01-26 21:30 ` Junio C Hamano
2017-01-26 21:53 ` Jeff King
2017-02-17 3:57 ` [PATCH 0/3] delete_ref(): support reflog messages Kyle Meyer
2017-02-17 3:57 ` [PATCH 1/3] delete_refs(): accept a reflog message argument Kyle Meyer
2017-02-17 8:12 ` Jeff King
2017-02-17 17:05 ` Junio C Hamano
2017-02-17 23:35 ` Kyle Meyer
2017-02-17 3:57 ` [PATCH 2/3] update-ref: pass reflog message argument to delete_refs Kyle Meyer
2017-02-17 8:22 ` Jeff King
2017-02-17 17:11 ` Junio C Hamano
2017-02-17 23:40 ` Kyle Meyer
2017-02-17 23:41 ` Jeff King
2017-02-17 3:58 ` Kyle Meyer [this message]
2017-02-17 8:31 ` [PATCH 3/3] rename_ref: replace empty deletion message in HEAD's log Jeff King
2017-02-17 17:50 ` Junio C Hamano
2017-02-17 19:43 ` Jeff King
2017-02-17 19:55 ` Jeff King
2017-02-17 22:18 ` Junio C Hamano
2017-02-17 23:42 ` Kyle Meyer
2017-02-17 23:41 ` Kyle Meyer
2017-02-17 23:53 ` Junio C Hamano
2017-02-17 23:53 ` Jeff King
2017-02-17 8:17 ` [PATCH 0/3] delete_ref(): support reflog messages Jeff King
2017-02-21 1:10 ` [PATCH v2 0/4] delete_ref: " Kyle Meyer
2017-02-21 1:10 ` [PATCH v2 1/4] delete_ref: accept a reflog message argument Kyle Meyer
2017-02-23 9:33 ` Duy Nguyen
2017-02-23 22:29 ` Junio C Hamano
2017-02-25 3:05 ` Kyle Meyer
2017-02-21 1:10 ` [PATCH v2 2/4] update-ref: pass reflog message to delete_ref() Kyle Meyer
2017-02-21 1:10 ` [PATCH v2 3/4] rename_ref: replace empty message in HEAD's log Kyle Meyer
2017-02-21 1:10 ` [PATCH v2 4/4] branch: record creation of renamed branch " Kyle Meyer
2017-02-21 7:12 ` [PATCH v2 0/4] delete_ref: support reflog messages Jeff King
2017-02-21 7:18 ` Junio C Hamano
2017-02-21 16:45 ` Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170217035800.13214-4-kyle@kyleam.com \
--to=kyle@kyleam.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).