git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Maw <richard.maw@codethink.co.uk>
To: git@vger.kernel.org
Subject: Some issues when trying to set up a shallow git mirror server
Date: Thu, 7 Jan 2016 16:54:17 +0000	[thread overview]
Message-ID: <20160107165417.GB3397@logi.codethink.co.uk> (raw)

Hi all.

I've been working on a service that mirrors open source code into git,
(http://git.baserock.org/cgi-bin/cgit.cgi/?q=delta if interested).

Some repositories are too unwieldy to mirror the whole history,
so we're looking at shallow support,
by fetching specified branches with `--depth=1`.

Since we'll be fetching in only a very shallow history,
we found that most of the time git classifies this as non-fast-forward.

I can see why this happens,
since it ends up with non-overlapping ranges of history
it hasn't fetched enough commits to join the dots.

This is inconvenient for us,
as we were explicitly using refspecs which didn't force the fetch,
since we were using the "non fast-forward update" errors
to detect whether upstream force pushed important refs
which could be a sign of tampering.

While the client doesn't have enough information
the server has those commits.
Would it make sense for the server to be able to tell the client
"trust me, that commit is a descendant of the previous one"?

Here's a patch to the test suite that demonstrates the failure,
since I felt I had to put some commands together to demonstrate,
and I may as well put it in a useful format.

diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh
index a980574..0996d12 100755
--- a/t/t5537-fetch-shallow.sh
+++ b/t/t5537-fetch-shallow.sh
@@ -186,4 +186,24 @@ EOF
 	test_cmp expect actual
 '
 
+test_expect_success 'fetch --depth with discontinuous history' '
+	git init --quiet --bare discontinuous.git &&
+	(
+	cd discontinuous.git &&
+	git fetch --quiet ../.git --depth=1 "refs/*:refs/*"
+	) &&
+	commit 5 &&
+	commit 6 &&
+	(
+	cd discontinuous.git &&
+	git fetch ../.git --depth=1 "refs/*:refs/*" &&
+	git fsck &&
+	git log --format=%s master >actual &&
+	cat <<EOF >expect &&
+6
+EOF
+	test_cmp expect actual
+	)
+'
+
 test_done

I also encountered weird behaviour when trying to push the history,
the general symptom being that the server would only update one ref,
so the client would fail because the server didn't mention all the refs.

diff --git a/t/t5538-push-shallow.sh b/t/t5538-push-shallow.sh
index ceee95b..d0bd538 100755
--- a/t/t5538-push-shallow.sh
+++ b/t/t5538-push-shallow.sh
@@ -120,4 +120,27 @@ EOF
 	git cat-file blob `echo 1|git hash-object --stdin` >/dev/null
 	)
 '
+
+test_expect_success 'push --mirror from shallow clone' '
+	git --git-dir=full/.git tag r0 &&
+	git init --quiet --bare mirror-pusher.git &&
+	git init --quiet --bare mirror.git &&
+	git --git-dir=mirror.git config receive.shallowUpdate true &&
+	(
+	cd mirror-pusher.git &&
+	git remote add --mirror=fetch origin ../full/.git &&
+	git remote add mirror ../mirror.git &&
+	git fetch --quiet origin --depth=1 &&
+	git push --mirror mirror
# The push should work, but does not.
# The following command works for creations, but not deletions.
#git for-each-ref -s --format "git push mirror +%(refname)" | sh
+	) &&
+	git --git-dir=mirror.git for-each-ref --format "%(refname)" --sort refname >actual &&
+	cat <<EOF >expect &&
+refs/heads/master
+refs/remotes/origin/HEAD
+refs/remotes/origin/master
+refs/tags/r0
+EOF
+	test_cmp expect actual
+'
+
 test_done

             reply	other threads:[~2016-01-07 16:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07 16:54 Richard Maw [this message]
2016-01-07 18:00 ` Some issues when trying to set up a shallow git mirror server Junio C Hamano
2016-01-08 10:19   ` Richard Maw
2016-01-08 10:44     ` Duy Nguyen
2016-01-08 10:52       ` Richard Maw
2016-01-08 21:37   ` Junio C Hamano
2016-01-11 15:51     ` Richard Maw
2016-01-12 18:29       ` Junio C Hamano
2016-01-13 11:37         ` Richard Maw
2016-01-13 17:14           ` Junio C Hamano
2016-01-13 17:43             ` Richard Maw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160107165417.GB3397@logi.codethink.co.uk \
    --to=richard.maw@codethink.co.uk \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).