0

I've got a repo structure like this:

main/
├── bicep/
│   └── modules/
│       ├── module1/
│       │   └── .tests/
│       │       └── main.bicep
│       └── main.bicep
└── main.bicep

I'm trying to run a git diff to only tell me what module files have been edited, with an extension of *.bicep, but exclude the .tests subfolder.

There will be a tests folder per module created.

My issue is I cannot seem to get git diff to even respect the folder I'm pointing it to using:

git diff HEAD HEAD~ --name-only -- *.bicep bicep/modules/

It will pick up commit changes under bicep/ and anywhere else however, I'm just trying to find a way to only check specifically under the /modules folder & exclude .tests folders, and only *.bicep extensions.

Running my current git diff command is picking up more than I'd like

PS C:\Repos\Lab> git diff HEAD HEAD~ --name-only -- *.bicep bicep/modules/ 
Bicep/main.bicep
Bicep/modules/storage/.tests/main.tests.bicep
Bicep/modules/storage/main.bicep

I can exclude a folder by adding

':!folder' 

but my tests folder is in a subfolder and main.bicep file from the main Bicep folder.

Any ideas?

Thanks!

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • Does this answer your question? [How to filter git diff based on file extensions?](https://stackoverflow.com/questions/8554776/how-to-filter-git-diff-based-on-file-extensions) – Liam Mar 13 '23 at 16:16
  • 1
    I've seen this article before I posted but couldn't work it out. However, looks like on review and a coffee I've cleared my head enough to get this to work using `find` and piping this like `find Bicep/modules -name '*.bicep' -type f -not -path '*/modules/*/.tests/*' -print0 | xargs -0 git diff HEAD HEAD~ --name-only` – riosengineer Mar 13 '23 at 16:59
  • Also seem to have got it with PowerShell as well now using `git diff HEAD HEAD~ --name-only -- Bicep/modules ":(exclude)*/.tests/*" | Where-Object {$_.EndsWith('.bicep')}` for anyone else interested – riosengineer Mar 13 '23 at 17:23

0 Answers0