forked from akuity/kargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(controller): git-push step: pull --rebase before push (akuity#3119)
Signed-off-by: Kent Rancourt <[email protected]> Co-authored-by: Hidde Beydals <[email protected]>
- Loading branch information
Showing
17 changed files
with
528 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package git | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// ErrMergeConflict is returned when a merge conflict occurs. | ||
var ErrMergeConflict = errors.New("merge conflict") | ||
|
||
// IsMergeConflict returns true if the error is a merge conflict or wraps one | ||
// and false otherwise. | ||
func IsMergeConflict(err error) bool { | ||
return errors.Is(err, ErrMergeConflict) | ||
} | ||
|
||
// ErrNonFastForward is returned when a push is rejected because it is not a | ||
// fast-forward or needs to be fetched first. | ||
var ErrNonFastForward = errors.New("non-fast-forward") | ||
|
||
// IsNonFastForward returns true if the error is a non-fast-forward or wraps one | ||
// and false otherwise. | ||
func IsNonFastForward(err error) bool { | ||
return errors.Is(err, ErrNonFastForward) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package git | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsMergeConflict(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
err error | ||
expected bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
expected: false, | ||
}, | ||
{ | ||
name: "not a merge conflict", | ||
err: errors.New("something went wrong"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "a merge conflict", | ||
err: ErrMergeConflict, | ||
expected: true, | ||
}, | ||
{ | ||
name: "a wrapped merge conflict", | ||
err: fmt.Errorf("an error occurred: %w", ErrMergeConflict), | ||
expected: true, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
actual := IsMergeConflict(testCase.err) | ||
require.Equal(t, testCase.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestIsNonFastForward(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
err error | ||
expected bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
expected: false, | ||
}, | ||
{ | ||
name: "not a non-fast-forward error", | ||
err: errors.New("something went wrong"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "a non-fast-forward error", | ||
err: ErrNonFastForward, | ||
expected: true, | ||
}, | ||
{ | ||
name: "a wrapped fast forward error", | ||
err: fmt.Errorf("an error occurred: %w", ErrNonFastForward), | ||
expected: true, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
actual := IsNonFastForward(testCase.err) | ||
require.Equal(t, testCase.expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package directives | ||
|
||
import "errors" | ||
|
||
// terminalError wraps another error to indicate to the step execution engine | ||
// that the step that produced the error should not be retried. | ||
type terminalError struct { | ||
err error | ||
} | ||
|
||
// Error implements the error interface. | ||
func (e *terminalError) Error() string { | ||
if e.err == nil { | ||
return "" | ||
} | ||
return e.err.Error() | ||
} | ||
|
||
// isTerminal returns true if the error is a terminal error or wraps one and | ||
// false otherwise. | ||
func isTerminal(err error) bool { | ||
te := &terminalError{} | ||
return errors.As(err, &te) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package directives | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsTerminal(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
err error | ||
expected bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
err: nil, | ||
expected: false, | ||
}, | ||
{ | ||
name: "not a terminal error", | ||
err: errors.New("something went wrong"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "a terminal error", | ||
err: &terminalError{err: errors.New("something went wrong")}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "a wrapped terminal error", | ||
err: fmt.Errorf( | ||
"an error occurred: %w", | ||
&terminalError{err: errors.New("something went wrong")}, | ||
), | ||
expected: true, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
actual := isTerminal(testCase.err) | ||
require.Equal(t, testCase.expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.