Signed-off-by: Christian Couder <[email protected]>
---
t/t0460-read-object-git.sh | 29 ++++++++++++++++++++
t/t0460/read-object-git | 67 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100755 t/t0460-read-object-git.sh
create mode 100755 t/t0460/read-object-git
diff --git a/t/t0460-read-object-git.sh b/t/t0460-read-object-git.sh
new file mode 100755
index 0000000000..d08b44cdce
--- /dev/null
+++ b/t/t0460-read-object-git.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+test_description='tests for long running read-object process passing git
objects'
+
+. ./test-lib.sh
+
+PATH="$PATH:$TEST_DIRECTORY/t0460"
+
+test_expect_success 'setup host repo with a root commit' '
+ test_commit zero &&
+ hash1=$(git ls-tree HEAD | grep zero.t | cut -f1 | cut -d\ -f3)
+'
+
+HELPER="read-object-git"
+
+test_expect_success 'blobs can be retrieved from the host repo' '
+ git init guest-repo &&
+ (cd guest-repo &&
+ git config odb.magic.command "$HELPER" &&
+ git config odb.magic.fetchKind "gitObject" &&
+ git cat-file blob "$hash1")
+'
+
+test_expect_success 'invalid blobs generate errors' '
+ cd guest-repo &&
+ test_must_fail git cat-file blob "invalid"
+'
+
+test_done
diff --git a/t/t0460/read-object-git b/t/t0460/read-object-git
new file mode 100755
index 0000000000..356a22cd4c
--- /dev/null
+++ b/t/t0460/read-object-git
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+#
+# Example implementation for the Git read-object protocol version 1
+# See Documentation/technical/read-object-protocol.txt
+#
+# Allows you to test the ability for blobs to be pulled from a host git repo
+# "on demand." Called when git needs a blob it couldn't find locally due to
+# a lazy clone that only cloned the commits and trees.
+#
+# A lazy clone can be simulated via the following commands from the host repo
+# you wish to create a lazy clone of:
+#
+# cd /host_repo
+# git rev-parse HEAD
+# git init /guest_repo
+# git cat-file --batch-check --batch-all-objects | grep -v 'blob' |
+# cut -d' ' -f1 | git pack-objects /e/guest_repo/.git/objects/pack/noblobs
+# cd /guest_repo
+# git config core.virtualizeobjects true
+# git reset --hard <sha from rev-parse call above>
+#
+# Please note, this sample is a minimal skeleton. No proper error handling
+# was implemented.
+#
+
+use 5.008;
+use lib (split(/:/, $ENV{GITPERLLIB}));
+use strict;
+use warnings;
+use Git::Packet;
+
+#
+# Point $DIR to the folder where your host git repo is located so we can pull
+# missing objects from it
+#
+my $DIR = "../.git/";
+
+packet_initialize("git-read-object", 1);
+
+packet_read_and_check_capabilities("get");
+packet_write_capabilities("get");
+
+while (1) {
+ my ($command) = packet_txt_read() =~ /^command=([^=]+)$/;
+
+ if ( $command eq "get" ) {
+ my ($sha1) = packet_txt_read() =~ /^sha1=([0-9a-f]{40})$/;
+ packet_bin_read();
+
+ my $path = $sha1;
+ $path =~ s{..}{$&/};
+ $path = $DIR . "/objects/" . $path;
+
+ my $contents = do {
+ local $/;
+ open my $fh, $path or die "Can't open '$path': $!";
+ <$fh>
+ };
+
+ packet_bin_write($contents);
+ packet_flush();
+ packet_txt_write("status=success");
+ packet_flush();
+ } else {
+ die "bad command '$command'";
+ }
+}
--
2.13.1.565.gbfcd7a9048