From a3c04fdcb7135f6b7f74e5b8747d04e6c28acd1e Mon Sep 17 00:00:00 2001 From: Oleg Utkin Date: Tue, 23 Nov 2021 11:17:49 -0700 Subject: [PATCH] WIP: Extend note copy procedure to respect notes.rewriteRef CLOSES #108 --- stgit/lib/git/repository.py | 6 +++- t/t2700-refresh.sh | 68 +++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 +- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/stgit/lib/git/repository.py b/stgit/lib/git/repository.py index fff3441b..58866107 100644 --- a/stgit/lib/git/repository.py +++ b/stgit/lib/git/repository.py @@ -483,5 +483,9 @@ def repack(self): def copy_notes(self, old_sha1, new_sha1): """Copy Git notes from the old object to the new one.""" - p = self.run(['git', 'notes', 'copy', old_sha1, new_sha1]) + p = self.run(['git', 'notes', 'copy', '--for-rewrite=stg']) + p.env({ + "GIT_NOTES_REWRITE_REF": "refs/notes/*" + }) + p.raw_input("{} {}".format(old_sha1, new_sha1)) p.discard_exitcode().discard_stderr().discard_output() diff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh index 2ef20dda..fd3521b0 100755 --- a/t/t2700-refresh.sh +++ b/t/t2700-refresh.sh @@ -4,6 +4,73 @@ test_description='Run "stg refresh"' . ./test-lib.sh +_setup_git_excludes() { + # Ignore our own temp files. + cat >> .git/info/exclude < note_rewrite_test/expected_notes.txt < note_rewrite_test/expected_extra_notes.txt < actual_notes.txt + test_cmp actual_notes.txt expected_notes.txt + git notes --ref refs/notes/extra show > actual_extra_notes.txt + test_cmp actual_extra_notes.txt expected_extra_notes.txt + + echo "base" >> file.txt + stg add file.txt + stg refresh --index + + # Verify notes are still set + git notes show > actual_notes.txt + test_cmp actual_notes.txt expected_notes.txt + git notes --ref refs/notes/extra show > actual_extra_notes.txt + test_cmp actual_extra_notes.txt expected_extra_notes.txt + ) +' + +# Delete temporary sub repo. +rm -rf note_rewrite_test + test_expect_success 'Initialize StGit stack' ' stg init && echo expected*.txt >> .git/info/exclude && @@ -34,6 +101,7 @@ test_expect_success 'Refresh top patch' ' stg refresh && test "$(git notes show)" = "note3" && stg status && + pwd && test -z "$(stg status)" && stg patches foo3.txt > patches.txt && test_cmp expected.txt patches.txt diff --git a/t/test-lib.sh b/t/test-lib.sh index cc8dde0c..47bce5f2 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -530,7 +530,7 @@ die () { # This is responsible for running the atexit commands even when a # test script run with '--immediate' fails, or when the user hits # ctrl-C, i.e. when 'test_done' is not invoked at all. - test_atexit_handler || code=$? + test_atexit_handler || code$? if test -n "$GIT_EXIT_OK" then exit $code