0

I have about 10 extensions that I want to add to the index with a script in my CI pipeline.

I know that git add supports file patterns such as *.c (the term used in the documentation is 'fileglob').

However, is there a way to add multiple extensions with a single command, e.g. git add *.{dll,exe,json}?

I have not found any examples in the documentation or Stack overflow about this issue.

torek
  • 448,244
  • 59
  • 642
  • 775
  • The syntax `*.{dll,exe,json}` is from [`bash`](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html). So if you use git-bash you can use the synax. In cmd just list extensions one by one: `git add *.dll *.exe *.json` – phd Dec 02 '22 at 12:12
  • 1
    Their CI almost certainly doesn't run Git Bash, but it's enough if they have Bash. However, it's quite possible that the automation only supports POSIX `sh`, in which case like you say they need to enumerate the wildcards separately. See also [Difference between `sh` and `bash`](https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash) – tripleee Dec 02 '22 at 12:19
  • My CI is an Azure Pipelines agent, that runs a Powershell script in a Windows Machine. Apologies, I should have clarified that. – Guillermo Ibáñez Dec 02 '22 at 14:42
  • I added the powershell tag, but you might want to update the question text itself to be specific about powershell here. – torek Dec 02 '22 at 20:16
  • According to [Microsoft's page](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser) you can run agents on any system you like, so it's difficult for anyone to guess how your agent, whatever it might be, uses whatever string Microsoft's UI passes to it. Git commands do accept multiple patterns; if you tried specifying them then the UI or the agent are passing them explicitly marked as a single pattern with embedded spaces. Yuck, and my sympathies, but you're going to have to say what specific tools you're using that might be doing this. – jthill Dec 02 '22 at 20:41

1 Answers1

0

In powershell this should be something like the following if you want to add files recursively:

Get-ChildItem -Recurse -Filter "*.dll" -or -Filter "*.exe" -or -Filter "*.json" | ForEach-Object { git add $_ }

(extend to your 10 extensions)

hlovdal
  • 26,565
  • 10
  • 94
  • 165