Thread (3 messages) 3 messages, 2 authors, 2016-06-15

Re: [PATCH v2] upload-pack: Optionally allow fetching reachable sha1

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:04:39

On Tue, May 5, 2015 at 5:21 PM, Fredrik Medley [off-list ref] wrote:
quoted hunk ↗ jump to hunk
With uploadpack.allowreachablesha1inwant configuration option set on the
server side, "git fetch" can make a request with a "want" line that names
an object that has not been advertised (likely to have been obtained out
of band or from a submodule pointer). Only objects reachable from the
branch tips, i.e. the union of advertised branches and branches hidden by
transfer.hiderefs, will be processed. Note that there is an associated
cost of having to walk back the hstory to check the reachability.
[...]
Signed-off-by: Fredrik Medley <redacted>
---
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 8a5f236..01fabfb 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1120,6 +1120,61 @@ test_expect_success 'fetch exact SHA1' '
        )
 '

+for configallowtipsha1inwant in true false
+do
+       test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
+               mk_empty testrepo &&
+               (
+                       cd testrepo &&
+                       git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
+                       git commit --allow-empty -m foo &&
+                       git commit --allow-empty -m bar
+               ) &&
+               SHA1=`git --git-dir=testrepo/.git rev-parse HEAD^` &&
Use $(..) here and elsewhere rather than `...`.

    SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
quoted hunk ↗ jump to hunk
+               mk_empty shallow &&
+               (
+                       cd shallow &&
+                       test_must_fail git fetch --depth=1 ../testrepo/.git $SHA1 &&
+                       git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
+                       git fetch --depth=1 ../testrepo/.git $SHA1 &&
+                       git cat-file commit $SHA1 >/dev/null
+               )
+       '
+
+       test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
+               mk_empty testrepo &&
+               (
+                       cd testrepo &&
+                       git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
+                       git commit --allow-empty -m foo &&
+                       git commit --allow-empty -m bar &&
+                       git commit --allow-empty -m xyz
+               )
+               SHA1_1=`git --git-dir=testrepo/.git rev-parse HEAD^^` &&
+               SHA1_2=`git --git-dir=testrepo/.git rev-parse HEAD^` &&
+               SHA1_3=`git --git-dir=testrepo/.git rev-parse HEAD` &&
+               (
+                       cd testrepo &&
+                       git reset --hard $SHA1_2 &&
+                       git cat-file commit $SHA1_3 >/dev/null &&
+                       git cat-file commit $SHA1_3 >/dev/null
+               ) &&
+               mk_empty shallow &&
+               (
+                       cd shallow &&
+                       test_must_fail git fetch ../testrepo/.git $SHA1_3 &&
+                       test_must_fail git fetch ../testrepo/.git $SHA1_1 &&
+                       git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
+                       git fetch ../testrepo/.git $SHA1_1 &&
+                       git cat-file commit $SHA1_1 >/dev/null &&
+                       test_must_fail git cat-file commit $SHA1_2 >/dev/null &&
+                       git fetch ../testrepo/.git $SHA1_2 &&
+                       git cat-file commit $SHA1_2 >/dev/null &&
+                       test_must_fail git fetch ../testrepo/.git $SHA1_3
+               )
+       '
+done
+
 test_expect_success 'fetch follows tags by default' '
        mk_test testrepo heads/master &&
        rm -fr src dst &&
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help