@babajide234/git-merge-workflow 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GitMergeWorkflow.psd1 +6 -1
- package/GitMergeWorkflow.psm1 +51 -29
- package/package.json +1 -1
package/GitMergeWorkflow.psd1
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@{
|
|
2
2
|
RootModule = 'GitMergeWorkflow.psm1'
|
|
3
|
-
ModuleVersion = '1.0.
|
|
3
|
+
ModuleVersion = '1.0.6'
|
|
4
4
|
GUID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
|
|
5
5
|
Author = 'babajide Tomoshegbo'
|
|
6
6
|
CompanyName = 'babajide234'
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
Tags = @('Git', 'Workflow', 'Automation', 'Merge', 'DevOps')
|
|
15
15
|
ProjectUri = 'https://github.com/babajide234/GitMergeWorkflow'
|
|
16
16
|
ReleaseNotes = @"
|
|
17
|
+
## 1.0.6
|
|
18
|
+
- Fix: Resolve false positive remote branch detection caused by git credential-manager stderr warnings polluting ls-remote output.
|
|
19
|
+
- Fix: Use full refs/heads/ refspec prefix in fetch command to prevent remote ref resolution failures.
|
|
20
|
+
- Improvement: Added fallback to create local branch if remote fetch fails unexpectedly.
|
|
21
|
+
|
|
17
22
|
## 1.0.5
|
|
18
23
|
- Fix: Ensure correct remote branch referencing and fetching by using full refspecs in ls-remote and fetch commands.
|
|
19
24
|
|
package/GitMergeWorkflow.psm1
CHANGED
|
@@ -20,7 +20,8 @@ function Get-GitWorkflowConfig {
|
|
|
20
20
|
return Get-Content $configPath -Raw | ConvertFrom-Json
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
24
25
|
Write-Verbose "Error reading config: $_"
|
|
25
26
|
}
|
|
26
27
|
return $null
|
|
@@ -41,7 +42,7 @@ function New-GitWorkflowConfig {
|
|
|
41
42
|
.EXAMPLE
|
|
42
43
|
New-GitWorkflowConfig -TargetBranch "main" -StagingSuffix "-test"
|
|
43
44
|
#>
|
|
44
|
-
[CmdletBinding(SupportsShouldProcess
|
|
45
|
+
[CmdletBinding(SupportsShouldProcess = $true)]
|
|
45
46
|
param(
|
|
46
47
|
[string]$TargetBranch = "develop",
|
|
47
48
|
[string]$StagingSuffix = "-staging",
|
|
@@ -58,9 +59,9 @@ function New-GitWorkflowConfig {
|
|
|
58
59
|
$configPath = Join-Path $gitRoot ".git-merge-workflow.json"
|
|
59
60
|
|
|
60
61
|
$config = @{
|
|
61
|
-
TargetBranch
|
|
62
|
+
TargetBranch = $TargetBranch
|
|
62
63
|
StagingSuffix = $StagingSuffix
|
|
63
|
-
Remote
|
|
64
|
+
Remote = $Remote
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
$json = $config | ConvertTo-Json -Depth 2
|
|
@@ -104,18 +105,18 @@ function Invoke-GitMergeWorkflow {
|
|
|
104
105
|
git-merge-workflow -CommitMessage "Feature: Added new component" -WhatIf
|
|
105
106
|
#>
|
|
106
107
|
|
|
107
|
-
[CmdletBinding(SupportsShouldProcess
|
|
108
|
+
[CmdletBinding(SupportsShouldProcess = $true)]
|
|
108
109
|
param(
|
|
109
|
-
[Parameter(Mandatory
|
|
110
|
+
[Parameter(Mandatory = $false)]
|
|
110
111
|
[string]$CommitMessage = "",
|
|
111
112
|
|
|
112
|
-
[Parameter(Mandatory
|
|
113
|
+
[Parameter(Mandatory = $false)]
|
|
113
114
|
[string]$StagingBranch = "",
|
|
114
115
|
|
|
115
|
-
[Parameter(Mandatory
|
|
116
|
+
[Parameter(Mandatory = $false)]
|
|
116
117
|
[string]$TargetBranch = "",
|
|
117
118
|
|
|
118
|
-
[Parameter(Mandatory
|
|
119
|
+
[Parameter(Mandatory = $false)]
|
|
119
120
|
[string]$Remote = ""
|
|
120
121
|
)
|
|
121
122
|
|
|
@@ -137,19 +138,19 @@ function Invoke-GitMergeWorkflow {
|
|
|
137
138
|
function Exec-Git {
|
|
138
139
|
[CmdletBinding()]
|
|
139
140
|
param(
|
|
140
|
-
[Parameter(Mandatory
|
|
141
|
+
[Parameter(Mandatory = $true, Position = 0)]
|
|
141
142
|
[string]$Command,
|
|
142
143
|
|
|
143
|
-
[Parameter(Mandatory
|
|
144
|
+
[Parameter(Mandatory = $false)]
|
|
144
145
|
[string]$ErrorMessage,
|
|
145
146
|
|
|
146
|
-
[Parameter(Mandatory
|
|
147
|
+
[Parameter(Mandatory = $false)]
|
|
147
148
|
[switch]$IgnoreError,
|
|
148
149
|
|
|
149
|
-
[Parameter(Mandatory
|
|
150
|
+
[Parameter(Mandatory = $false)]
|
|
150
151
|
[switch]$ReturnOutput,
|
|
151
152
|
|
|
152
|
-
[Parameter(ValueFromRemainingArguments
|
|
153
|
+
[Parameter(ValueFromRemainingArguments = $true)]
|
|
153
154
|
[string[]]$Arguments
|
|
154
155
|
)
|
|
155
156
|
|
|
@@ -163,7 +164,8 @@ function Invoke-GitMergeWorkflow {
|
|
|
163
164
|
|
|
164
165
|
if ($ReturnOutput) {
|
|
165
166
|
return $output
|
|
166
|
-
}
|
|
167
|
+
}
|
|
168
|
+
elseif ($output) {
|
|
167
169
|
# If not capturing output, write it to the stream (except errors which we handle below)
|
|
168
170
|
$output | ForEach-Object { Write-Verbose $_ }
|
|
169
171
|
}
|
|
@@ -181,7 +183,8 @@ function Invoke-GitMergeWorkflow {
|
|
|
181
183
|
# Check if we're in a git repository
|
|
182
184
|
try {
|
|
183
185
|
Exec-Git "rev-parse" "--is-inside-work-tree" -ErrorMessage "Not a git repository" -ReturnOutput | Out-Null
|
|
184
|
-
}
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
185
188
|
Write-Error $_.Exception.Message
|
|
186
189
|
return
|
|
187
190
|
}
|
|
@@ -234,7 +237,8 @@ function Invoke-GitMergeWorkflow {
|
|
|
234
237
|
Exec-Git "commit" "-m" "$CommitMessage" -ErrorMessage "Failed to commit changes"
|
|
235
238
|
Write-Host "Changes committed!" -ForegroundColor Green
|
|
236
239
|
}
|
|
237
|
-
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
238
242
|
Write-Error "You have uncommitted changes! Please commit them first or use -CommitMessage parameter"
|
|
239
243
|
git status
|
|
240
244
|
return
|
|
@@ -247,24 +251,38 @@ function Invoke-GitMergeWorkflow {
|
|
|
247
251
|
$branchExists = git branch --list $StagingBranch
|
|
248
252
|
if (-not $branchExists) {
|
|
249
253
|
Write-Host "`nStaging branch doesn't exist locally. Checking remote..." -ForegroundColor Yellow
|
|
250
|
-
# Check if exists on remote
|
|
254
|
+
# Check if exists on remote using a direct git command to avoid
|
|
255
|
+
# false positives from stderr warnings (e.g. credential-manager)
|
|
251
256
|
$remoteBranchExists = $false
|
|
252
257
|
try {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
258
|
+
# Use & git directly so stderr warnings don't pollute the result.
|
|
259
|
+
# ls-remote --heads returns lines like "<hash>\trefs/heads/<branch>" for matches.
|
|
260
|
+
$lsOutput = & git ls-remote --heads $Remote "refs/heads/$StagingBranch" 2>$null
|
|
261
|
+
if ($lsOutput -and $lsOutput -match "refs/heads/$([regex]::Escape($StagingBranch))") {
|
|
262
|
+
$remoteBranchExists = $true
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
256
266
|
Write-Warning "Could not check remote branch: $_"
|
|
257
267
|
}
|
|
258
268
|
|
|
259
269
|
if ($remoteBranchExists) {
|
|
260
270
|
Write-Host "Fetching remote staging branch..." -ForegroundColor Yellow
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
271
|
+
try {
|
|
272
|
+
Exec-Git -Command "fetch" -Arguments $Remote, "refs/heads/${StagingBranch}:refs/remotes/$Remote/$StagingBranch"
|
|
273
|
+
Exec-Git -Command "checkout" -Arguments "-b", $StagingBranch, "$Remote/$StagingBranch"
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
Write-Warning "Failed to fetch remote staging branch. Creating new local branch instead."
|
|
277
|
+
Exec-Git -Command "checkout" -Arguments "-b", $StagingBranch
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
264
281
|
Write-Host "Creating new staging branch..." -ForegroundColor Yellow
|
|
265
282
|
Exec-Git -Command "checkout" -Arguments "-b", $StagingBranch
|
|
266
283
|
}
|
|
267
|
-
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
268
286
|
Write-Host "Checking out staging branch..." -ForegroundColor Yellow
|
|
269
287
|
Exec-Git -Command "checkout" -Arguments $StagingBranch
|
|
270
288
|
}
|
|
@@ -285,12 +303,14 @@ function Invoke-GitMergeWorkflow {
|
|
|
285
303
|
try {
|
|
286
304
|
Exec-Git -Command "push" -Arguments "-u", $Remote, $StagingBranch -ErrorMessage "Failed to push staging branch"
|
|
287
305
|
Write-Host "Staging branch pushed!" -ForegroundColor Green
|
|
288
|
-
}
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
289
308
|
Write-Warning "Failed to push staging branch to remote."
|
|
290
309
|
Write-Warning "Error: $_"
|
|
291
310
|
if ($PSCmdlet.ShouldContinue("Do you want to skip pushing the staging branch and continue to merge into $TargetBranch?", "Skip Staging Push")) {
|
|
292
311
|
Write-Host "Skipping staging push..." -ForegroundColor Yellow
|
|
293
|
-
}
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
294
314
|
throw $_
|
|
295
315
|
}
|
|
296
316
|
}
|
|
@@ -321,10 +341,12 @@ function Invoke-GitMergeWorkflow {
|
|
|
321
341
|
Write-Host " ✓ Merged: $originalBranch → $StagingBranch → $TargetBranch" -ForegroundColor White
|
|
322
342
|
Write-Host " ✓ All changes pushed to remote`n" -ForegroundColor White
|
|
323
343
|
|
|
324
|
-
}
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
325
346
|
Write-Error $_.Exception.Message
|
|
326
347
|
Write-Host "`nWorkflow failed. Attempting to return to original branch..." -ForegroundColor Red
|
|
327
|
-
}
|
|
348
|
+
}
|
|
349
|
+
finally {
|
|
328
350
|
# Return to original branch
|
|
329
351
|
$finalBranch = (git branch --show-current).Trim()
|
|
330
352
|
if ($originalBranch -and $finalBranch -ne $originalBranch) {
|