Skip to content

Commit

Permalink
WIP: Extend note copy procedure to respect notes.rewriteRef
Browse files Browse the repository at this point in the history
  • Loading branch information
NonLogicalDev committed Nov 24, 2021
1 parent d5bef96 commit a3c04fd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
6 changes: 5 additions & 1 deletion stgit/lib/git/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
68 changes: 68 additions & 0 deletions t/t2700-refresh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,73 @@ test_description='Run "stg refresh"'

. ./test-lib.sh

_setup_git_excludes() {
# Ignore our own temp files.
cat >> .git/info/exclude <<EOF
expected*.txt
actual*.txt
patches*.txt
show*.txt
diff*.txt
files*.txt
status*.txt
EOF
}

test_expect_success '(note_rewrite_test) Initialize Sub-Repo' '
test_create_repo note_rewrite_test &&
( set -ex; cd note_rewrite_test;
_setup_git_excludes
stg init
# [WARNING]:
# At the moment the tests fail without the following configuration options set.
# TODO: need backwards compatibility.
# git config notes.rewriteRef "refs/notes/*"
# [/WARNING]
# This setting can be enabled or disabled, but it defaults to true.
# git config notes.rewrite.stg true
# This setting appends note contents to `git show`. Can specify a glob to list all notes.
# git config notes.displayref "refs/notes/*"
)
'

cat > note_rewrite_test/expected_notes.txt <<EOF
note0
EOF
cat > note_rewrite_test/expected_extra_notes.txt <<EOF
extra_note0
EOF
test_expect_success '(note_rewrite_test) Test that Stg refresh preserves default and extra git notes' '
( set -ex; cd note_rewrite_test;
# Create base patch with a few notes.
stg new p0 -m "base"
git notes add -m note0
git notes --ref refs/notes/extra add -m extra_note0 &&
# Verify notes are 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
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 &&
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3c04fd

Please sign in to comment.