builtin/clone: compute checkout metadata for clones
When checking out a commit, provide metadata to the filter process including the ref we're using. Signed-off-by: brian m. carlson <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 16, 2020 at 18:05 UTC
dfc8cdc6772a05db4ed64c45df3fe2defdae7eb3
2 files changed
+11
-4
builtin/clone.c
+4
-1
@@ -780,11 +780,11 @@ static int checkout(int submodule_progress)
780
if (!strcmp(head, "HEAD")) {
781
if (advice_detached_head)
782
detach_advice(oid_to_hex(&oid));
783
+ FREE_AND_NULL(head);
784
} else {
785
if (!starts_with(head, "refs/heads/"))
786
die(_("HEAD not found below refs/heads!"));
787
}
787
- free(head);
788
789
/* We need to be in the new work tree for the checkout */
790
setup_work_tree();
@@ -799,6 +799,7 @@ static int checkout(int submodule_progress)
799
opts.verbose_update = (option_verbosity >= 0);
800
opts.src_index = &the_index;
801
opts.dst_index = &the_index;
802
+ init_checkout_metadata(&opts.meta, head, &oid, NULL);
803
804
tree = parse_tree_indirect(&oid);
805
parse_tree(tree);
@@ -806,6 +807,8 @@ static int checkout(int submodule_progress)
807
if (unpack_trees(1, &t, &opts) < 0)
808
die(_("unable to checkout working tree"));
809
810
+ free(head);
811
+
812
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
813
die(_("unable to write new index file"));
814
t/t0021-conversion.sh
+7
-3
@@ -748,7 +748,8 @@ test_expect_success PERL 'delayed checkout in process filter' '
748
) &&
749
750
S=$(file_size "$TEST_ROOT/test.o") &&
751
- M="blob=$(git -C repo rev-parse --verify master:test.a)" &&
751
+ PM="ref=refs/heads/master treeish=$(git -C repo rev-parse --verify master) " &&
752
+ M="${PM}blob=$(git -C repo rev-parse --verify master:test.a)" &&
753
cat >a.exp <<-EOF &&
754
START
755
init handshake complete
@@ -789,8 +790,11 @@ test_expect_success PERL 'delayed checkout in process filter' '
790
791
rm *.a *.b &&
792
filter_git checkout . &&
792
- test_cmp_count ../a.exp a.log &&
793
- test_cmp_count ../b.exp b.log &&
793
+ # We are not checking out a ref here, so filter out ref metadata.
794
+ sed -e "s!$PM!!" ../a.exp >a.exp.filtered &&
795
+ sed -e "s!$PM!!" ../b.exp >b.exp.filtered &&
796
+ test_cmp_count a.exp.filtered a.log &&
797
+ test_cmp_count b.exp.filtered b.log &&
798
799
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
800
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&