Skip to content

Commit

Permalink
base: Honor .gitignore for rsync
Browse files Browse the repository at this point in the history
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.

Use `git ls-files` to honor `.gitignore`.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jun 21, 2024
1 parent 90bdfc6 commit 8e951c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import re
import shutil
import subprocess
import sys
import tempfile
import time
Expand Down Expand Up @@ -1796,7 +1797,14 @@ 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))
excludes_tempfile = tempfile.NamedTemporaryFile()
# If we're in a git repository, honor .gitignore; xref
# https://stackoverflow.com/questions/13713101/rsync-exclude-according-to-gitignore-hgignore-svnignore-like-filter-c
if os.path.isdir(f"{tree_root}/.git"):
subprocess.check_call(["git", "ls-files", "--exclude-standard", "-oi", "--directory"], stdout=excludes_tempfile)
# Note: rsync doesn't use reflinks right now, so in the future it'd be even better to
# use e.g. `cp` but filtering out the above.
self.run(Command("rsync", "-ar", "--exclude", ".git", "--exclude-from", excludes_tempfile.name, f"{tree_root}/", self.worktree))

def _initialize_data_directory(self) -> None:
"""
Expand Down

0 comments on commit 8e951c2

Please sign in to comment.