THX-1138
THX-1138

Reputation: 21730

Use powershell to run a command for changed files in git

I want to use jb cleanupcode --include .\file1;.\file2 to only format code that has changed. I.e. I want to run git diff --name-only and then feed the output to the jb cleanupcode command using its --include flag.

The issue is that git diff --name-only produces a list of files one-per-line.

Question: how do I take a stream of path-per-file and turn it into a semicolon-separated list fed to a command?

Upvotes: 1

Views: 604

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

Use the -join operator to join the resulting paths together:

$names = @(git diff --name-only) -join ';'
jb cleanupcode --include $names

Or as a single statement:

jb cleanupcode --include (@(git diff --name-only) -join ';')

Upvotes: 2

Related Questions