Skip to content

Commit

Permalink
Merge branch 'th/push-local-ff-check-without-lazy-fetch'
Browse files Browse the repository at this point in the history
When "git push" notices that the commit at the tip of the ref on
the other side it is about to overwrite does not exist locally, it
used to first try fetching it if the local repository is a partial
clone. The command has been taught not to do so and immediately
fail instead.

* th/push-local-ff-check-without-lazy-fetch:
  push: don't fetch commit object when checking existence
  • Loading branch information
gitster committed Jun 3, 2024
2 parents 5c7c063 + 6549c41 commit eb6392f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
else if (!repo_has_object_file(the_repository, &ref->old_oid))
else if (!repo_has_object_file_with_flags(the_repository, &ref->old_oid, OBJECT_INFO_SKIP_FETCH_OBJECT))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
Expand Down
19 changes: 19 additions & 0 deletions t/t0410-partial-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,25 @@ test_expect_success 'lazy-fetch when accessing object not in the_repository' '
! grep "[?]$FILE_HASH" out
'

test_expect_success 'push should not fetch new commit objects' '
rm -rf server client &&
test_create_repo server &&
test_config -C server uploadpack.allowfilter 1 &&
test_config -C server uploadpack.allowanysha1inwant 1 &&
test_commit -C server server1 &&
git clone --filter=blob:none "file://$(pwd)/server" client &&
test_commit -C client client1 &&
test_commit -C server server2 &&
COMMIT=$(git -C server rev-parse server2) &&
test_must_fail git -C client push 2>err &&
grep "fetch first" err &&
git -C client rev-list --objects --missing=print "$COMMIT" >objects &&
grep "^[?]$COMMIT" objects
'

. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd

Expand Down

0 comments on commit eb6392f

Please sign in to comment.