aboutsummaryrefslogtreecommitdiffstats
path: root/t/t1460-refs-migrate.sh
diff options
context:
space:
mode:
authorKarthik Nayak <karthik.188@gmail.com>2024-12-16 17:44:33 +0100
committerJunio C Hamano <gitster@pobox.com>2024-12-16 09:45:34 -0800
commit246cebe3205694ce19eceaa795d20f24ba762c49 (patch)
treeed5b2da3ac8df97bde77536aa1f5329be0c6a62a /t/t1460-refs-migrate.sh
parentrefs: allow multiple reflog entries for the same refname (diff)
downloadgit-246cebe3205694ce19eceaa795d20f24ba762c49.tar.gz
git-246cebe3205694ce19eceaa795d20f24ba762c49.zip
refs: add support for migrating reflogs
The `git refs migrate` command was introduced in 25a0023f28 (builtin/refs: new command to migrate ref storage formats, 2024-06-06) to support migrating from one reference backend to another. One limitation of the command was that it didn't support migrating repositories which contained reflogs. A previous commit, added support for adding reflog updates in ref transactions. Using the added functionality bake in reflog support for `git refs migrate`. To ensure that the order of the reflogs is maintained during the migration, we add the index for each reflog update as we iterate over the reflogs from the old reference backend. This is to ensure that the order is maintained in the new backend. Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rwxr-xr-xt/t1460-refs-migrate.sh73
1 files changed, 51 insertions, 22 deletions
diff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh
index 1bfff3a7af..f59bc4860f 100755
--- a/t/t1460-refs-migrate.sh
+++ b/t/t1460-refs-migrate.sh
@@ -7,23 +7,44 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
+# 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>
+# <repo> is the relative path to the repo to be migrated.
+# <format> is the ref format to be migrated to.
+# <skip_reflog_verify> (true or false) whether to skip reflog verification.
test_migration () {
- git -C "$1" for-each-ref --include-root-refs \
+ repo=$1 &&
+ format=$2 &&
+ skip_reflog_verify=${3:-false} &&
+ git -C "$repo" for-each-ref --include-root-refs \
--format='%(refname) %(objectname) %(symref)' >expect &&
- git -C "$1" refs migrate --ref-format="$2" &&
- git -C "$1" for-each-ref --include-root-refs \
+ if ! $skip_reflog_verify
+ then
+ git -C "$repo" reflog --all >expect_logs &&
+ git -C "$repo" reflog list >expect_log_list
+ fi &&
+
+ git -C "$repo" refs migrate --ref-format="$2" &&
+
+ git -C "$repo" for-each-ref --include-root-refs \
--format='%(refname) %(objectname) %(symref)' >actual &&
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
+ fi &&
- git -C "$1" rev-parse --show-ref-format >actual &&
- echo "$2" >expect &&
+ git -C "$repo" rev-parse --show-ref-format >actual &&
+ echo "$format" >expect &&
test_cmp expect actual
}
test_expect_success 'setup' '
- rm -rf .git &&
- # The migration does not yet support reflogs.
- git config --global core.logAllRefUpdates false
+ rm -rf .git
'
test_expect_success "superfluous arguments" '
@@ -78,19 +99,6 @@ do
test_cmp expect err
'
- test_expect_success "$from_format -> $to_format: migration with reflog fails" '
- test_when_finished "rm -rf repo" &&
- git init --ref-format=$from_format repo &&
- test_config -C repo core.logAllRefUpdates true &&
- test_commit -C repo logged &&
- test_must_fail git -C repo refs migrate \
- --ref-format=$to_format 2>err &&
- cat >expect <<-EOF &&
- error: migrating reflogs is not supported yet
- EOF
- test_cmp expect err
- '
-
test_expect_success "$from_format -> $to_format: migration with worktree fails" '
test_when_finished "rm -rf repo" &&
git init --ref-format=$from_format repo &&
@@ -141,7 +149,7 @@ do
test_commit -C repo initial &&
test-tool -C repo ref-store main update-ref "" refs/heads/broken \
"$(test_oid 001)" "$ZERO_OID" REF_SKIP_CREATE_REFLOG,REF_SKIP_OID_VERIFICATION &&
- test_migration repo "$to_format" &&
+ test_migration repo "$to_format" true &&
test_oid 001 >expect &&
git -C repo rev-parse refs/heads/broken >actual &&
test_cmp expect actual
@@ -195,6 +203,27 @@ do
git -C repo rev-parse --show-ref-format >actual &&
test_cmp expect actual
'
+
+ test_expect_success "$from_format -> $to_format: reflogs of symrefs with target deleted" '
+ test_when_finished "rm -rf repo" &&
+ git init --ref-format=$from_format repo &&
+ test_commit -C repo initial &&
+ git -C repo branch branch-1 HEAD &&
+ git -C repo symbolic-ref refs/heads/symref refs/heads/branch-1 &&
+ cat >input <<-EOF &&
+ delete refs/heads/branch-1
+ EOF
+ git -C repo update-ref --stdin <input &&
+ test_migration repo "$to_format"
+ '
+
+ test_expect_success "$from_format -> $to_format: reflogs order is retained" '
+ test_when_finished "rm -rf repo" &&
+ git init --ref-format=$from_format repo &&
+ test_commit --date "100005000 +0700" --no-tag -C repo initial &&
+ test_commit --date "100003000 +0700" --no-tag -C repo second &&
+ test_migration repo "$to_format"
+ '
done
done