Skip to content

Commit dfc8cdc

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13e7ed6 commit dfc8cdc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

builtin/clone.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,11 @@ static int checkout(int submodule_progress)
780780
if (!strcmp(head, "HEAD")) {
781781
if (advice_detached_head)
782782
detach_advice(oid_to_hex(&oid));
783+
FREE_AND_NULL(head);
783784
} else {
784785
if (!starts_with(head, "refs/heads/"))
785786
die(_("HEAD not found below refs/heads!"));
786787
}
787-
free(head);
788788

789789
/* We need to be in the new work tree for the checkout */
790790
setup_work_tree();
@@ -799,13 +799,16 @@ static int checkout(int submodule_progress)
799799
opts.verbose_update = (option_verbosity >= 0);
800800
opts.src_index = &the_index;
801801
opts.dst_index = &the_index;
802+
init_checkout_metadata(&opts.meta, head, &oid, NULL);
802803

803804
tree = parse_tree_indirect(&oid);
804805
parse_tree(tree);
805806
init_tree_desc(&t, tree->buffer, tree->size);
806807
if (unpack_trees(1, &t, &opts) < 0)
807808
die(_("unable to checkout working tree"));
808809

810+
free(head);
811+
809812
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
810813
die(_("unable to write new index file"));
811814

t/t0021-conversion.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ test_expect_success PERL 'delayed checkout in process filter' '
748748
) &&
749749
750750
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)" &&
752753
cat >a.exp <<-EOF &&
753754
START
754755
init handshake complete
@@ -789,8 +790,11 @@ test_expect_success PERL 'delayed checkout in process filter' '
789790
790791
rm *.a *.b &&
791792
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 &&
794798
795799
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
796800
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&

0 commit comments

Comments
 (0)