Skip to content

Commit

Permalink
Fix a problem with newer Git extracting repo roots, older Git not sup…
Browse files Browse the repository at this point in the history
…porting filtering
  • Loading branch information
benfitzpatrick committed Mar 14, 2024
1 parent ff398b4 commit afddb2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
19 changes: 9 additions & 10 deletions metomi/rose/loc_handlers/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ def parse(self, loc, conf_tree):
async def pull(self, loc, conf_tree):
"""Get loc to its cache.
We would strongly prefer to use git sparse-checkout (with
filtered clones) but it is not available on many systems (Git
>= 2.25) and it is still marked as experimental.
git sparse-checkout is not available below Git 2.25, and seems to omit
contents altogether if set to the root of the repo (as of 2.40.1).
"""
if not loc.real_name:
Expand All @@ -149,20 +148,20 @@ async def pull(self, loc, conf_tree):
await self.manager.popen.run_ok_async(
"git", git_dir_opt, "remote", "add", "origin", remote
)
if self.git_version >= (2, 25, 0):
if self.git_version >= (2, 25, 0) and path != "./":
await self.manager.popen.run_ok_async(
"git", git_dir_opt, "sparse-checkout", "set", path,
"--no-cone"
)
await self.manager.popen.run_ok_async(
"git", git_dir_opt, "fetch", "--depth=1", "--filter=blob:none",
"origin", loc.key
)
else:
await self.manager.popen.run_ok_async(
"git", git_dir_opt, "config", "extensions.partialClone",
"true"
"git", git_dir_opt, "fetch", "--depth=1", "origin", loc.key
)
await self.manager.popen.run_ok_async(
"git", git_dir_opt, "fetch", "--depth=1", "--filter=blob:none",
"origin", loc.key
)

await self.manager.popen.run_ok_async(
"git", git_dir_opt, f"--work-tree={tmpdirname}", "checkout",
loc.key
Expand Down
4 changes: 3 additions & 1 deletion sphinx/api/configuration/file-creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ root directory to install file targets with a relative path:
branch, or long commit hash to specify the commit at which you want
to extract. These should follow the same semantics as if you git
cloned ``REPOSITORY_URL``, git checkout'ed ``TREEISH``, and extracted
the path ``PATHSPEC`` within the clone.
the path ``PATHSPEC`` within the clone. To extract from the root of
the repository use a ``PATHSPEC`` of ``./`` e.g.
``git:git@github.com:metomi/rose::./::2.2.0``.
:opt rsync: This scheme is useful for pulling a file or directory from
a remote host using ``rsync`` via ``ssh``. A URI should have the
form ``HOST:PATH``.
Expand Down
21 changes: 20 additions & 1 deletion t/rose-app-run/28-git.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ GIT_WS_PID=${!}
sleep 10
cd $START_PWD
#-------------------------------------------------------------------------------
tests 49
tests 51
#-------------------------------------------------------------------------------
remote_test_modes=("ssh" "http" "local")
remote_locations=("$HOSTNAME:$TEST_DIR/hellorepo/" "http://localhost:$GIT_WS_PORT/cgi-bin/git" "$TEST_DIR/hellorepo/")
Expand Down Expand Up @@ -177,6 +177,25 @@ find hello -type f -newer timeline | LANG=C sort >'find-hello-after-newer.out'
file_cmp "$TEST_KEY.find-hello-newer" 'find-hello-after-newer.out' </dev/null
test_teardown
#-------------------------------------------------------------------------------
TEST_KEY="$TEST_KEY_BASE-entire-contents"
test_setup
test_init <<__CONFIG__
[command]
default=true
[file:hello]
source=git:$TEST_DIR/hellorepo::./::$MAIN_BRANCH
__CONFIG__
run_pass "$TEST_KEY" rose app-run --config=../config -q
find hello -type f | LANG=C sort >'find-hello.out'
file_cmp "$TEST_KEY.find" 'find-hello.out' <<__FILE__
hello/fruit/orange.txt
hello/fruit/raspberry.txt
hello/grass.txt
hello/tree.txt
__FILE__
test_teardown
#-------------------------------------------------------------------------------
TEST_KEY="$TEST_KEY_BASE-bad-ref"
test_setup
test_init <<__CONFIG__
Expand Down

0 comments on commit afddb2b

Please sign in to comment.