Integration test highlighting failure during git pull with tag in GRit server

Summary:
The negotiation part of the git protocol involves the client specifying its `WANTS` and `HAVES` and the server realizing the set of objects to send to satisfy the client's need. The first version of the server expected only commit Object Ids as part of `WANTS` and as a result it failed straight away in the presence of tags. The current version of the server allows for tag Object Ids as part of `WANTS` but it converts it into commits pointed to by the tag. That works in the cases when the commit pointed to by the tag is part of the packfile being sent by the server.

If the packfile does not include the commit that the tag points to, then we completely omit sending the tag even though the client explicitly requested it. This integration test highlights that we do not support this behavior yet and fail with a fatal in such a case. I will fix this in a follow up diff along with an updated integration test.

Reviewed By: mitrandir77

Differential Revision: D56979846

fbshipit-source-id: 4cff34b4d5ba55a652b91d57ce5ac95a1ca0b162
This commit is contained in:
Rajiv Sharma 2024-05-07 03:11:41 -07:00 committed by Facebook GitHub Bot
parent cd3d2615b1
commit a0a7a9129d

View File

@ -0,0 +1,86 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License found in the LICENSE file in the root
# directory of this source tree.
$ . "${TEST_FIXTURES}/library.sh"
$ REPOTYPE="blob_files"
$ ENABLED_DERIVED_DATA='["git_commits", "git_trees", "git_delta_manifests", "unodes", "filenodes", "hgchangesets"]' setup_common_config $REPOTYPE
$ GIT_REPO_ORIGIN="${TESTTMP}/origin/repo-git"
$ GIT_REPO="${TESTTMP}/repo-git"
$ HG_REPO="${TESTTMP}/repo-hg"
$ BUNDLE_PATH="${TESTTMP}/repo_bundle.bundle"
$ cat >> repos/repo/server.toml <<EOF
> [source_control_service]
> permit_writes = true
> EOF
# Setup git repository
$ mkdir -p "$GIT_REPO_ORIGIN"
$ cd "$GIT_REPO_ORIGIN"
$ git init -q
$ echo "this is fileA" > fileA
$ git add fileA
$ git commit -qam "Add fileA"
$ old_head=$(git rev-parse HEAD)
$ git tag -a -m"new tag" first_tag
$ echo "this is fileA.1" > fileA
$ echo "this is fileB" > fileB
$ git add .
$ git commit -qam "Modified fileA -> fileA.1, Add fileB"
$ git tag -a empty_tag -m ""
$ cd "$TESTTMP"
$ git clone "$GIT_REPO_ORIGIN"
Cloning into 'repo-git'...
done.
# Capture all the known Git objects from the repo
$ cd $GIT_REPO
$ current_head=$(git rev-parse HEAD)
$ git rev-list --objects --all | git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' | sort > $TESTTMP/object_list
# Import it into Mononoke
$ cd "$TESTTMP"
$ quiet gitimport "$GIT_REPO" --derive-hg --generate-bookmarks full-repo
# Start up the Mononoke Git Service
$ mononoke_git_service
# Clone the Git repo from Mononoke
$ git_client clone $MONONOKE_GIT_SERVICE_BASE_URL/$REPONAME.git
Cloning into 'repo'...
# Verify that we get the same Git repo back that we started with
$ cd $REPONAME
$ git rev-list --objects --all | git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' | sort > $TESTTMP/new_object_list
$ diff -w $TESTTMP/new_object_list $TESTTMP/object_list
# Add more commits to the original git repo
$ cd $GIT_REPO_ORIGIN
$ echo "this is fileC" > fileC
$ git add fileC
$ git commit -qam "Add fileC"
$ echo "this is fileD" > fileD
$ git add fileD
$ git commit -qam "Add fileD"
# Create a tag pointing to an older commit that will NOT be part of the response from the server to the client
$ git tag -a -m "tag pointing to an older commit" tag_in_past $old_head
$ cd "$GIT_REPO"
$ quiet git pull "$GIT_REPO_ORIGIN"
# Capture all the known Git objects from the repo
$ cd $GIT_REPO_ORIGIN
$ git rev-list --objects --all | git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' | sort > $TESTTMP/object_list
# Import the newly added commits to Mononoke
$ cd "$TESTTMP"
$ quiet gitimport "$GIT_REPO_ORIGIN" --derive-hg --generate-bookmarks full-repo
# Pull the Git repo from Mononoke
$ cd $REPONAME
# Wait for the warm bookmark cache to catch up with the latest changes
$ wait_for_git_bookmark_move HEAD $current_head
$ quiet git_client pull
fatal: bad object 113454d6c6f11b84d16c504f75e39fca4c522f00
error: https://*/repos/git/ro/repo.git did not send all necessary objects (glob)
[1]