mirror of
https://github.com/git/git.git
synced 2026-04-12 01:40:10 +02:00
Merge branch 'ps/reflog-migrate-fixes' into maint-2.51
"git refs migrate" to migrate the reflog entries from a refs backend to another had a handful of bugs squashed. * ps/reflog-migrate-fixes: refs: fix invalid old object IDs when migrating reflogs refs: stop unsetting REF_HAVE_OLD for log-only updates refs/files: detect race when generating reflog entry for HEAD refs: fix identity for migrated reflogs ident: fix type of string length parameter builtin/reflog: implement subcommand to write new entries refs: export `ref_transaction_update_reflog()` builtin/reflog: improve grouping of subcommands Documentation/git-reflog: convert to use synopsis type
This commit is contained in:
@@ -204,6 +204,7 @@ integration_tests = [
|
||||
't1418-reflog-exists.sh',
|
||||
't1419-exclude-refs.sh',
|
||||
't1420-lost-found.sh',
|
||||
't1421-reflog-write.sh',
|
||||
't1430-bad-ref-name.sh',
|
||||
't1450-fsck.sh',
|
||||
't1451-fsck-buffer.sh',
|
||||
|
||||
126
t/t1421-reflog-write.sh
Executable file
126
t/t1421-reflog-write.sh
Executable file
@@ -0,0 +1,126 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='Manually write reflog entries'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
SIGNATURE="C O Mitter <committer@example.com> 1112911993 -0700"
|
||||
|
||||
test_reflog_matches () {
|
||||
repo="$1" &&
|
||||
refname="$2" &&
|
||||
cat >actual &&
|
||||
test-tool -C "$repo" ref-store main for-each-reflog-ent "$refname" >expected &&
|
||||
test_cmp expected actual
|
||||
}
|
||||
|
||||
test_expect_success 'invalid number of arguments' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
for args in "" "1" "1 2" "1 2 3" "1 2 3 4 5"
|
||||
do
|
||||
test_must_fail git reflog write $args 2>err &&
|
||||
test_grep "usage: git reflog write" err || return 1
|
||||
done
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'invalid refname' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_must_fail git reflog write "refs/heads/ invalid" $ZERO_OID $ZERO_OID first 2>err &&
|
||||
test_grep "invalid reference name: " err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'unqualified refname is rejected' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_must_fail git reflog write unqualified $ZERO_OID $ZERO_OID first 2>err &&
|
||||
test_grep "invalid reference name: " err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'nonexistent object IDs' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_must_fail git reflog write refs/heads/something $(test_oid deadbeef) $ZERO_OID old-object-id 2>err &&
|
||||
test_grep "old object .* does not exist" err &&
|
||||
test_must_fail git reflog write refs/heads/something $ZERO_OID $(test_oid deadbeef) new-object-id 2>err &&
|
||||
test_grep "new object .* does not exist" err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'abbreviated object IDs' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit initial &&
|
||||
abbreviated_oid=$(git rev-parse HEAD | test_copy_bytes 8) &&
|
||||
test_must_fail git reflog write refs/heads/something $abbreviated_oid $ZERO_OID old-object-id 2>err &&
|
||||
test_grep "invalid old object ID" err &&
|
||||
test_must_fail git reflog write refs/heads/something $ZERO_OID $abbreviated_oid new-object-id 2>err &&
|
||||
test_grep "invalid new object ID" err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog message gets normalized' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit initial &&
|
||||
COMMIT_OID=$(git rev-parse HEAD) &&
|
||||
git reflog write HEAD $COMMIT_OID $COMMIT_OID "$(printf "message\nwith\nnewlines")" &&
|
||||
git reflog show -1 --format=%gs HEAD >actual &&
|
||||
echo "message with newlines" >expected &&
|
||||
test_cmp expected actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'simple writes' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit initial &&
|
||||
COMMIT_OID=$(git rev-parse HEAD) &&
|
||||
|
||||
git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
|
||||
test_reflog_matches . refs/heads/something <<-EOF &&
|
||||
$ZERO_OID $COMMIT_OID $SIGNATURE first
|
||||
EOF
|
||||
|
||||
git reflog write refs/heads/something $COMMIT_OID $COMMIT_OID second &&
|
||||
test_reflog_matches . refs/heads/something <<-EOF
|
||||
$ZERO_OID $COMMIT_OID $SIGNATURE first
|
||||
$COMMIT_OID $COMMIT_OID $SIGNATURE second
|
||||
EOF
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'can write to root ref' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit initial &&
|
||||
COMMIT_OID=$(git rev-parse HEAD) &&
|
||||
|
||||
git reflog write ROOT_REF_HEAD $ZERO_OID $COMMIT_OID first &&
|
||||
test_reflog_matches . ROOT_REF_HEAD <<-EOF
|
||||
$ZERO_OID $COMMIT_OID $SIGNATURE first
|
||||
EOF
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
@@ -7,6 +7,17 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
print_all_reflog_entries () {
|
||||
repo=$1 &&
|
||||
test-tool -C "$repo" ref-store main for-each-reflog >reflogs &&
|
||||
while read reflog
|
||||
do
|
||||
echo "REFLOG: $reflog" &&
|
||||
test-tool -C "$repo" ref-store main for-each-reflog-ent "$reflog" ||
|
||||
return 1
|
||||
done <reflogs
|
||||
}
|
||||
|
||||
# Migrate the provided repository from one format to the other and
|
||||
# verify that the references and logs are migrated over correctly.
|
||||
# Usage: test_migration <repo> <format> [<skip_reflog_verify> [<options...>]]
|
||||
@@ -28,8 +39,7 @@ test_migration () {
|
||||
--format='%(refname) %(objectname) %(symref)' >expect &&
|
||||
if ! $skip_reflog_verify
|
||||
then
|
||||
git -C "$repo" reflog --all >expect_logs &&
|
||||
git -C "$repo" reflog list >expect_log_list
|
||||
print_all_reflog_entries "$repo" >expect_logs
|
||||
fi &&
|
||||
|
||||
git -C "$repo" refs migrate --ref-format="$format" "$@" &&
|
||||
@@ -39,10 +49,8 @@ test_migration () {
|
||||
test_cmp expect actual &&
|
||||
if ! $skip_reflog_verify
|
||||
then
|
||||
git -C "$repo" reflog --all >actual_logs &&
|
||||
git -C "$repo" reflog list >actual_log_list &&
|
||||
test_cmp expect_logs actual_logs &&
|
||||
test_cmp expect_log_list actual_log_list
|
||||
print_all_reflog_entries "$repo" >actual_logs &&
|
||||
test_cmp expect_logs actual_logs
|
||||
fi &&
|
||||
|
||||
git -C "$repo" rev-parse --show-ref-format >actual &&
|
||||
@@ -273,7 +281,7 @@ test_expect_success 'multiple reftable blocks with multiple entries' '
|
||||
test_commit -C repo second &&
|
||||
printf "update refs/heads/ref-%d HEAD\n" $(test_seq 3000) >stdin &&
|
||||
git -C repo update-ref --stdin <stdin &&
|
||||
test_migration repo reftable
|
||||
test_migration repo reftable true
|
||||
'
|
||||
|
||||
test_expect_success 'migrating from files format deletes backend files' '
|
||||
|
||||
Reference in New Issue
Block a user