Skip to content

Commit 60c38e6

Browse files
committed
release: clean git worktree before checking for missing backports
Previously, we used `git status --porcelain` to check for uncommitted changes in the worktree. However, this approach was not reliable, as it could lead to false positives or negatives in certain situations. Instead, we now use `git clead -fd` to explicitly clean the worktree before checking for missing backports. Epic: none Release note: none
1 parent 35fbea7 commit 60c38e6

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

pkg/cmd/release/git.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,9 @@ func isAncestor(ref1, ref2 string) (bool, error) {
338338
// Returns true if the merge commit introduces changes, false if not, and error if the command fails.
339339
func mergeCreatesContentChanges(branch, intoBranch string, ignoredPatterns []string) (bool, error) {
340340
// Make sure the working directory is clean
341-
statusCmd := exec.Command("git", "status", "--porcelain")
342-
if out, err := statusCmd.Output(); err != nil {
343-
return false, fmt.Errorf("checking git status: %w", err)
344-
} else if len(out) > 0 {
345-
return false, fmt.Errorf("working directory is not clean")
341+
if err := exec.Command("git", "clean", "-fd").Run(); err != nil {
342+
return false, fmt.Errorf("cleaning working directory: %w", err)
346343
}
347-
348344
// Get the current branch name before we start
349345
currentBranchCmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
350346
currentBranch, err := currentBranchCmd.Output()
@@ -391,10 +387,6 @@ func mergeCreatesContentChanges(branch, intoBranch string, ignoredPatterns []str
391387
if err := exec.Command("git", "checkout", originalBranch).Run(); err != nil {
392388
return false, fmt.Errorf("running original branch checkout: %w", err)
393389
}
394-
if err := exec.Command("git", "branch", "-D", tmpIntoBranch).Run(); err != nil {
395-
return false, fmt.Errorf("deleting tmp branch: %w", err)
396-
}
397-
398390
// If diff returns no error (exit code 0), there are no changes
399391
// If diff returns error with exit code 1, there are changes
400392
// Any other error is unexpected

0 commit comments

Comments
 (0)