Skip to content

Commit e72171f

Browse files
derrickstoleegitster
authored andcommitted
bundle: test unbundling with incomplete history
When verifying a bundle, Git checks first that all prerequisite commits exist in the object store, then adds an additional check: those prerequisite commits must be reachable from references in the repository. This check is stronger than what is checked for refs being added during 'git fetch', which simply guarantees that the new refs have a complete history up to the point where it intersects with the current reachable history. However, we also do not have any tests that check the behavior under this condition. Create a test that demonstrates its behavior. In order to construct a broken history, perform a shallow clone of a repository with a linear history, but whose default branch ('base') has a single commit, so dropping the shallow markers leaves a complete history from that reference. However, the 'tip' reference adds a shallow commit whose parent is missing in the cloned repository. Trying to unbundle a bundle with the 'tip' as a prerequisite will succeed past the object store check and move into the reachability check. The two errors that are reported are of this form: error: Could not read <missing-commit> fatal: Failed to traverse parents of commit <present-commit> These messages are not particularly helpful for the person running the unbundle command, but they do prevent the command from succeeding. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d4e241a commit e72171f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

t/t6020-bundle-misc.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,44 @@ test_expect_success 'cloning from filtered bundle has useful error' '
559559
grep "cannot clone from filtered bundle" err
560560
'
561561

562+
test_expect_success 'verify catches unreachable, broken prerequisites' '
563+
test_when_finished rm -rf clone-from clone-to &&
564+
git init clone-from &&
565+
(
566+
cd clone-from &&
567+
git checkout -b base &&
568+
test_commit A &&
569+
git checkout -b tip &&
570+
git commit --allow-empty -m "will drop by shallow" &&
571+
git commit --allow-empty -m "will keep by shallow" &&
572+
git commit --allow-empty -m "for bundle, not clone" &&
573+
git bundle create tip.bundle tip~1..tip &&
574+
git reset --hard HEAD~1 &&
575+
git checkout base
576+
) &&
577+
BAD_OID=$(git -C clone-from rev-parse tip~1) &&
578+
TIP_OID=$(git -C clone-from rev-parse tip) &&
579+
git clone --depth=1 --no-single-branch \
580+
"file://$(pwd)/clone-from" clone-to &&
581+
(
582+
cd clone-to &&
583+
584+
# Set up broken history by removing shallow markers
585+
git update-ref -d refs/remotes/origin/tip &&
586+
rm .git/shallow &&
587+
588+
# Verify should fail
589+
test_must_fail git bundle verify \
590+
../clone-from/tip.bundle 2>err &&
591+
grep "Could not read $BAD_OID" err &&
592+
grep "Failed to traverse parents of commit $TIP_OID" err &&
593+
594+
# Unbundling should fail
595+
test_must_fail git bundle unbundle \
596+
../clone-from/tip.bundle 2>err &&
597+
grep "Could not read $BAD_OID" err &&
598+
grep "Failed to traverse parents of commit $TIP_OID" err
599+
)
600+
'
601+
562602
test_done

0 commit comments

Comments
 (0)