|
77 | 77 | } |
78 | 78 |
|
79 | 79 | $argumentNumber = 0 |
| 80 | + |
| 81 | + $gitArgsArray = [Collections.ArrayList]::new($GitArgument) |
| 82 | + |
80 | 83 | foreach ($commandElement in $callingContext.CommandElements) { |
81 | | - if ($commandElement.parameterName -in 'd', 'v') { |
82 | | - # If they passed -d/-D or -v/-V, they probably don't mean -Debug/-Verbose |
83 | | - $beforeArgs = @(if ($argumentNumber) { $GitArgument[0..$argumentNumber]}) |
84 | | - $afterArgs = @(if ($argumentNumber + 1 -le $gitArgument.Length) { |
85 | | - $GitArgument[($argumentNumber + 1)..($GitArgument.Length - 1)] |
86 | | - }) |
87 | | - $GitArgument = @($beforeArgs) + @("$($commandElement.Extent)") + @($afterArgs) |
88 | | - if ($commandElement.parameterName -eq 'd') { # Also, if they passed -d/-D, they probably don't want to be confirmed |
| 84 | + if ($commandElement.parameterName -in 'd', 'v', 'c') { |
| 85 | + # Insert the argument into the list |
| 86 | + $gitArgsArray.Insert( |
| 87 | + $argumentNumber - 1, # ( don't forget to subtract one, because the command is an element) |
| 88 | + $commandElement.Extent.ToString() |
| 89 | + ) |
| 90 | + if ($commandElement.parameterName -in 'd', 'c') { |
89 | 91 | $ConfirmPreference ='none' # so set confirm impact to none |
90 | | - } |
| 92 | + } |
91 | 93 | } |
92 | 94 | $argumentNumber++ |
93 | 95 | } |
94 | 96 |
|
| 97 | + $GitArgument = $gitArgsArray.ToArray() |
| 98 | + |
95 | 99 | $progId = Get-Random |
96 | 100 | $dirCount = 0 |
97 | | - $RepoNotRequired = 'clone','init','version','help' # A small number of git operations do not require a repo. List them here. |
| 101 | + # A small number of git operations do not require a repo. List them here. |
| 102 | + $RepoNotRequired = 'clone','init','version','help','-C' |
98 | 103 | } |
99 | | - process { |
| 104 | + |
| 105 | + process { |
100 | 106 | # First, we need to take any input and figure out what directories we are going into. |
101 | 107 | $directories = @() |
102 | 108 | $inputObject = |
|
122 | 128 |
|
123 | 129 | # Before we process each directory, make a copy of the bound parameters. |
124 | 130 | $paramCopy = ([Ordered]@{} + $PSBoundParameters) |
125 | | - |
| 131 | + if ($GitArgument -contains '-c' -or $GitArgument -contains '-C') { |
| 132 | + $paramCopy.Remove('Confirm') |
| 133 | + } |
126 | 134 |
|
127 | 135 | # Now, we will force there to be at least one directory (the current path). |
128 | 136 | # This makes the code simpler, because we are always going thru a loop. |
129 | | - if (-not $directories) { |
130 | | - $directories = @($pwd) |
| 137 | + if (-not $directories) { |
| 138 | + if ($GitArgument -ccontains '-C') { |
| 139 | + $directories = $gitArgument[$GitArgument.IndexOf('-C') + 1] |
| 140 | + } else { |
| 141 | + $directories = @($pwd) |
| 142 | + } |
131 | 143 | } else { |
132 | 144 | # It also gives us a change to normalize the directories into their full paths. |
133 | 145 | $directories = @(foreach ($dir in $directories) { $dir.Fullname }) |
134 | 146 | } |
135 | 147 |
|
| 148 | + |
| 149 | + |
136 | 150 |
|
137 | 151 | # For each directory we know of, we |
138 | 152 | foreach ($dir in $directories) { |
|
163 | 177 | Write-Progress -PercentComplete (($dirCount * 5) % 100) -Status "git $allGitArgs " -Activity "$($dir) " -Id $progId |
164 | 178 | } |
165 | 179 |
|
166 | | - if (($ConfirmPreference -eq 'None' -and -not $paramCopy.Confirm) -or # If we have indicated we do not care about -Confirmation, don't prompt |
| 180 | + # If we have indicated we do not care about -Confirmation, don't prompt |
| 181 | + if (($ConfirmPreference -eq 'None' -and (-not $paramCopy.Confirm)) -or |
167 | 182 | $PSCmdlet.ShouldProcess("$pwd : git $allGitArgs") # otherwise, as for confirmation to run. |
168 | 183 | ) { |
169 | 184 | $eventSourceIds = @("Use-Git","Use-Git $allGitArgs") |
|
0 commit comments