From de922669ab0508109cdb5672e5515f7524e3ccf8 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 20 Feb 2017 20:10:33 -0500 Subject: update-ref: pass reflog message to delete_ref() Now that delete_ref() accepts a reflog message, pass the user-provided message to delete_ref() rather than silently dropping it. Signed-off-by: Kyle Meyer Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 't') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index b0ffc0b573..6e112fb5f9 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -85,6 +85,24 @@ test_expect_success "delete $m (by HEAD)" ' ' rm -f .git/$m +test_expect_success "deleting current branch adds message to HEAD's log" ' + git update-ref $m $A && + git symbolic-ref HEAD $m && + git update-ref -m delete-$m -d $m && + ! test -f .git/$m && + grep "delete-$m$" .git/logs/HEAD +' +rm -f .git/$m + +test_expect_success "deleting by HEAD adds message to HEAD's log" ' + git update-ref $m $A && + git symbolic-ref HEAD $m && + git update-ref -m delete-by-head -d HEAD && + ! test -f .git/$m && + grep "delete-by-head$" .git/logs/HEAD +' +rm -f .git/$m + test_expect_success 'update-ref does not create reflogs by default' ' test_when_finished "git update-ref -d $outside" && git update-ref $outside $A && -- cgit v1.2.3 From 893dbf5ba16c47c7284209bc6c527195f368ee35 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 20 Feb 2017 20:10:34 -0500 Subject: rename_ref: replace empty message in HEAD's log 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_ref() accepts a reflog message, provide a more descriptive message by passing along the log message that is given to rename_ref(). The next step will be to extend HEAD's log to also include the second part of the rename, the creation of the new branch. Helped-by: Jeff King Signed-off-by: Kyle Meyer Signed-off-by: Junio C Hamano --- t/t3200-branch.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't') diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 8a833f354e..47bc151280 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -139,6 +139,11 @@ 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' ' + msg="Branch: renamed refs/heads/baz to refs/heads/bam" && + grep " 0\{40\}.*$msg$" .git/logs/HEAD +' + 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 && -- cgit v1.2.3 From 39ee4c6c2fc80960094ae1454922c2d10c72f210 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 20 Feb 2017 20:10:35 -0500 Subject: branch: record creation of renamed branch in HEAD's log Renaming the current branch adds an event to the current branch's log and to HEAD's log. However, the logged entries differ. The entry in the branch's log represents the entire renaming operation (the old and new hash are identical), whereas the entry in HEAD's log represents the deletion only (the new sha1 is null). Extend replace_each_worktree_head_symref(), whose only caller is branch_rename(), to take a reflog message argument. This allows the creation of the new ref to be recorded in HEAD's log. As a result, the renaming event is represented by two entries (a deletion and a creation entry) in HEAD's log. It's a bit unfortunate that the branch's log and HEAD's log now represent the renaming event in different ways. Given that the renaming operation is not atomic, the two-entry form is a more accurate representation of the operation and is more useful for debugging purposes if a failure occurs between the deletion and creation events. It would make sense to move the branch's log to the two-entry form, but this would involve changes to how the rename is carried out and to how the update flags and reflogs are processed for deletions, so it may not be worth the effort. Based-on-patch-by: Jeff King Signed-off-by: Kyle Meyer Signed-off-by: Junio C Hamano --- t/t3200-branch.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 47bc151280..e36ed3b4e1 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -139,9 +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' ' +test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' ' msg="Branch: renamed refs/heads/baz to refs/heads/bam" && - grep " 0\{40\}.*$msg$" .git/logs/HEAD + grep " 0\{40\}.*$msg$" .git/logs/HEAD && + grep "^0\{40\}.*$msg$" .git/logs/HEAD ' test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' ' -- cgit v1.2.3