1

A script which just wants a lean copy of the current state from the server to process further does this as an alternative to a shallow clone:

git archive --remote=ssh://example.com/repo.git --output=repo.tar.gz HEAD -- "*.hpp" "*.cpp" "*.inc"

If that repo happens to not have files for one of the wildcards, the whole operation fails:

remote: fatal: pathspec '*.inc' did not match any files
fatal: sent error to the client: git upload-archive: archiver died with error
remote: git upload-archive: archiver died with error

Is there a generic way to ignore certain pathspecs if they would throw an error otherwise? Without such filter it downloads just too much.

There are patterns in pathspecs including 'glob', but I couldn't find out how to make a logical "OR" or a regular expression.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Borph
  • 842
  • 1
  • 6
  • 17
  • 1
    Pathspecs are globs, not regular expressions, and are not capable of doing what you'd like here. The only way to tell whether this is going to fail is either to clone the repository and verify it locally (defeating the purpose) or to try it and see. – torek Feb 01 '22 at 10:20
  • It does seem a bit off that `git archive` will refuse to work with the same set of pathspecs all other commands I can find accept. `git ls-files` will list any matching files and ignore nonmatching wildcards, `git log` will list commits touching any matching files and ignore wildcards matching nothing, and so on. – jthill Feb 02 '22 at 00:24
  • >5min update: ah. okay, checkout with paths won't check out anything if you try to check out a pack of files including any specs that match nothing. This is judgment-call territory anyway, it's just how paranoid the commands want to be. – jthill Feb 02 '22 at 02:32
  • 1
    Ugh why is this cogent, well-asked and completely reasonable question downvoted?! That’s just abusive. – Konrad Rudolph Feb 02 '22 at 09:02

0 Answers0