Skip to content

Commit 0f97029

Browse files
committed
fix: improve branch reference handling for kustomize-diff
Signed-off-by: Steven Wade <[email protected]>
1 parent 4ceac70 commit 0f97029

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

kustdiff

+6-14
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ function safe_filename() {
3939
echo "$1" | sed 's/[^a-zA-Z0-9.]/_/g'
4040
}
4141

42-
function git_with_error_handling() {
43-
if ! "$@"; then
44-
echo "Error executing git command: $*"
45-
return 1
46-
fi
47-
return 0
48-
}
49-
5042
function build_ref {
5143
local ref="$1"
5244
local output_dir="$2"
@@ -71,7 +63,7 @@ function main {
7163
validate_root_dir
7264
validate_max_depth
7365

74-
git_with_error_handling git config --global --add safe.directory "$GITHUB_WORKSPACE"
66+
git config --global --add safe.directory "$GITHUB_WORKSPACE" || true
7567

7668
# Save current state to restore later
7769
local current_branch
@@ -123,13 +115,13 @@ function main {
123115
local merge_branch="temp-merge-$RANDOM"
124116
git checkout -b "$merge_branch" "$base_ref_resolved" --quiet
125117

126-
debug_log "Creating temporary merge of $head_ref_to_use into $base_ref_to_use (via $merge_branch)"
118+
debug_log "Creating temporary merge of $head_ref_resolved into $base_ref_resolved (via $merge_branch)"
127119

128120
# Attempt to merge HEAD into BASE
129-
if ! git merge "$head_ref_to_use" --quiet; then
130-
echo "Merge conflict detected. Cannot automatically merge $head_ref_to_use into $base_ref_to_use."
121+
if ! git merge "$head_ref_resolved" --quiet; then
122+
echo "Merge conflict detected. Cannot automatically merge $INPUT_HEAD_REF into $INPUT_BASE_REF."
131123
git merge --abort || true
132-
git checkout "$current_branch" --quiet || git checkout "$base_ref_to_use" --quiet || true
124+
git checkout "$current_branch" --quiet || git checkout "$base_ref_resolved" --quiet || true
133125
exit 1
134126
fi
135127

@@ -149,7 +141,7 @@ function main {
149141
debug_log "------------------------------------"
150142

151143
# Clean up temporary branches
152-
git checkout "$current_branch" --quiet || git checkout "$base_ref_to_use" --quiet || true
144+
git checkout "$current_branch" --quiet || git checkout "$base_ref_resolved" --quiet || true
153145
git branch -D "$merge_branch" --quiet || true
154146

155147
if [[ $diff_exit_code -eq 0 ]]; then

0 commit comments

Comments
 (0)