Skip to content

Commit 24ecfdf

Browse files
committed
Merge branch 'tb/fix-persistent-shallow' into master
When "fetch.writeCommitGraph" configuration is set in a shallow repository and a fetch moves the shallow boundary, we wrote out broken commit-graph files that do not match the reality, which has been corrected. * tb/fix-persistent-shallow: commit.c: don't persist substituted parents when unshallowing
2 parents 46be023 + ce16364 commit 24ecfdf

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

commit-graph.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ static int commit_graph_compatible(struct repository *r)
203203
}
204204

205205
prepare_commit_graft(r);
206-
if (r->parsed_objects && r->parsed_objects->grafts_nr)
206+
if (r->parsed_objects &&
207+
(r->parsed_objects->grafts_nr || r->parsed_objects->substituted_parent))
207208
return 0;
208209
if (is_repository_shallow(r))
209210
return 0;

commit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
423423
pptr = &item->parents;
424424

425425
graft = lookup_commit_graft(r, &item->object.oid);
426+
if (graft)
427+
r->parsed_objects->substituted_parent = 1;
426428
while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
427429
struct commit *new_parent;
428430

object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct parsed_object_pool {
2525
char *alternate_shallow_file;
2626

2727
int commit_graft_prepared;
28+
int substituted_parent;
2829

2930
struct buffer_slab *buffer_slab;
3031
};

t/t5537-fetch-shallow.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ test_expect_success 'fetch --unshallow from shallow clone' '
8181
)
8282
'
8383

84+
test_expect_success 'fetch --unshallow from a full clone' '
85+
git clone --no-local --depth=2 .git shallow3 &&
86+
(
87+
cd shallow3 &&
88+
git log --format=%s >actual &&
89+
test_write_lines 4 3 >expect &&
90+
test_cmp expect actual &&
91+
git -c fetch.writeCommitGraph fetch --unshallow &&
92+
git log origin/master --format=%s >actual &&
93+
test_write_lines 4 3 2 1 >expect &&
94+
test_cmp expect actual
95+
)
96+
'
97+
8498
test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' '
8599
# the blob "1" is available in .git but hidden by the
86100
# shallow2/.git/shallow and it should be resent

0 commit comments

Comments
 (0)