git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v7 09/13] rebase: support automatic notes copying

From
Thomas Rast <trast@student.ethz.ch>
Date
Mar 12, 2010, 17:04 UTC
Message-ID
<f69e4f9e1a5e9bca056573e24b97e37f251330e8.1268413246.git.trast@student.ethz.ch>
In-Reply-To
<cover.1268413246.git.trast@student.ethz.ch>
Luckily, all the support already happens to be there.
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 git-am.sh                     |    5 ++++-
 git-rebase--interactive.sh    |    4 ++++
 git-rebase.sh                 |    1 +
 t/t3400-rebase.sh             |   17 +++++++++++++++++
 t/t3404-rebase-interactive.sh |   24 ++++++++++++++++++++++++
 5 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 9b73e0b..1056075 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -797,8 +797,11 @@ do
 	go_next
 done
 
-if test -s "$dotest"/rewritten && test -x "$GIT_DIR"/hooks/post-rewrite; then
+if test -s "$dotest"/rewritten; then
+    git notes copy --for-rewrite=rebase < "$dotest"/rewritten
+    if test -x "$GIT_DIR"/hooks/post-rewrite; then
 	"$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
+    fi
 fi
 
 rm -fr "$dotest"
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f18a118..a57f043 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -561,6 +561,10 @@ do_next () {
 		test ! -f "$DOTEST"/verbose ||
 			git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
 	} &&
+	{
+		git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" ||
+		true # we don't care if this copying failed
+	} &&
 	if test -x "$GIT_DIR"/hooks/post-rewrite &&
 		test -s "$REWRITTEN_LIST"; then
 		"$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
diff --git a/git-rebase.sh b/git-rebase.sh
index 52f8b9b..e0eb956 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -152,6 +152,7 @@ move_to_original_branch () {
 
 finish_rb_merge () {
 	move_to_original_branch
+	git notes copy --for-rewrite=rebase < "$dotest"/rewritten
 	if test -x "$GIT_DIR"/hooks/post-rewrite &&
 		test -s "$dotest"/rewritten; then
 		"$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 4314ad2..dbf7dfb 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -151,4 +151,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' '
 	git diff --exit-code file-with-cr:CR HEAD:CR
 '
 
+test_expect_success 'rebase can copy notes' '
+	git config notes.rewrite.rebase true &&
+	git config notes.rewriteRef "refs/notes/*" &&
+	test_commit n1 &&
+	test_commit n2 &&
+	test_commit n3 &&
+	git notes add -m"a note" n3 &&
+	git rebase --onto n1 n2 &&
+	test "a note" = "$(git notes show HEAD)"
+'
+
+test_expect_success 'rebase -m can copy notes' '
+	git reset --hard n3 &&
+	git rebase -m --onto n1 n2 &&
+	test "a note" = "$(git notes show HEAD)"
+'
+
 test_done
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 4e35137..19668c2 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -553,4 +553,28 @@ test_expect_success 'reword' '
 	git show HEAD~2 | grep "C changed"
 '
 
+test_expect_success 'rebase -i can copy notes' '
+	git config notes.rewrite.rebase true &&
+	git config notes.rewriteRef "refs/notes/*" &&
+	test_commit n1 &&
+	test_commit n2 &&
+	test_commit n3 &&
+	git notes add -m"a note" n3 &&
+	git rebase --onto n1 n2 &&
+	test "a note" = "$(git notes show HEAD)"
+'
+
+cat >expect <<EOF
+an earlier note
+a note
+EOF
+
+test_expect_success 'rebase -i can copy notes over a fixup' '
+	git reset --hard n3 &&
+	git notes add -m"an earlier note" n2 &&
+	GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
+	git notes show > output &&
+	test_cmp expect output
+'
+
 test_done
-- 
1.7.0.2.417.gbc354
Previous: Thomas RastNext: Thomas Rast
Message 14 of 18 in “tr/display-notes”
  1. 00/13 tr/display-notesThomas Rast, Mar 12, 2010
  2. 01/13 test-lib: unset GIT_NOTES_REF to stop it from influencing testsThomas Rast, Mar 12, 2010
  3. 02/13 Support showing notes from more than one notes treeThomas Rast, Mar 12, 2010
  4. 03/13 Documentation: document post-rewrite hookThomas Rast, Mar 12, 2010
  5. 04/13 commit --amend: invoke post-rewrite hookThomas Rast, Mar 12, 2010
  6. 05/13 rebase: invoke post-rewrite hookThomas Rast, Mar 12, 2010
  7. 06/13 rebase -i: invoke post-rewrite hookThomas Rast, Mar 12, 2010
  8. 07/13 notes: implement 'git notes copy --stdin'Thomas Rast, Mar 12, 2010
  9. notes: Initialize variable to appease Sun StudioÆvar Arnfjörð Bjarmason, Jun 14, 2010
  10. Junio C HamanoJun 19, 2010
  11. Ævar Arnfjörð BjarmasonJun 19, 2010
  12. Ramsay JonesJun 21, 2010
  13. 08/13 notes: implement helpers needed for note copying during rewriteThomas Rast, Mar 12, 2010
  14. 09/13 rebase: support automatic notes copyingThomas Rast, Mar 12, 2010
  15. 10/13 commit --amend: copy notes to the new commitThomas Rast, Mar 12, 2010
  16. 11/13 notes: add shorthand --ref to override GIT_NOTES_REFThomas Rast, Mar 12, 2010
  17. 12/13 notes: track whether notes_trees were changed at allThomas Rast, Mar 12, 2010
  18. 13/13 git-notes(1): add a section about the meaning of historyThomas Rast, Mar 12, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.