From cc593906c22bd093233481172c15eba24598dae1 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 21 Jun 2024 07:27:17 -0400 Subject: [PATCH] base: Clone git repo if present instead of rsync I am guessing I may be one of the first people to try using tmt with a Rust project. The default for the `cargo` toolchain is to keep a *lot* of cached incremental data in `target/`. In my case with bootc, it's currently 20G. A plain rsync() of this is *incredibly* inefficient. rsync doesn't even use reflinks if available, though that's a distinct bug. Change the logic here to do a `git clone -s` which is *way* more efficient; it properly honors my `.gitignore` which includes `target/`. Signed-off-by: Colin Walters --- tmt/base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tmt/base.py b/tmt/base.py index 375c61d285..d5e48bd1f1 100644 --- a/tmt/base.py +++ b/tmt/base.py @@ -1796,7 +1796,12 @@ def _initialize_worktree(self) -> None: # Sync metadata root to the worktree self.debug(f"Sync the worktree to '{self.worktree}'.", level=2) - self.run(Command("rsync", "-ar", "--exclude", ".git", f"{tree_root}/", self.worktree)) + # If we're in a git repository, we just clone it so that we correctly + # honor .gitignore, etc. + if os.path.isdir(f"{tree_root}/.git"): + self.run(Command("git", "clone", "-s", tree_root, self.worktree)) + else: + self.run(Command("rsync", "-ar", "--exclude", ".git", f"{tree_root}/", self.worktree)) def _initialize_data_directory(self) -> None: """