Skip to content

Commit a652cca

Browse files
author
Pedro Pombeiro
committed
fix(gdk): propagate exit codes from git push helpers
gpsup, git_push_issue, and rebase_all now exit with code 1 on failure so callers (e.g., run-in-tmux-pane) correctly detect errors and return full output.
1 parent 1ea26a0 commit a652cca

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

.shellrc/zshrc.d/functions/scripts/git-helpers.rb

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -210,42 +210,42 @@ def rebase_mappings
210210
preload_threads.each(&:join)
211211

212212
local_branches = local_branches.sort_by do |branch|
213-
seq_mr_match_data = seq_mr_pattern.match(branch)
214-
backport_match_data = backport_pattern.match(branch)
215-
mr_match_data = mr_pattern.match(branch)
216-
217-
if seq_mr_match_data
218-
# Sort by: [branch_distance, mr_id, seq_nr, branch_name]
219-
# This ensures branches are grouped by MR and ordered by sequence within each MR
220-
[
221-
branch_distance(branch, default_branch),
222-
seq_mr_match_data[:mr_id].to_i,
223-
seq_mr_match_data[:mr_seq_nr].to_i,
224-
branch
225-
]
226-
elsif backport_match_data
227-
[
228-
branch_distance(branch, default_branch),
229-
backport_match_data[:mr_id].to_i,
230-
999, # Put backport branches after sequenced branches
231-
backport_match_data[:milestone].tr(".", "-").to_f
232-
]
233-
elsif mr_match_data
234-
[
235-
branch_distance(branch, default_branch),
236-
mr_match_data[:mr_id].to_i,
237-
999, # Put non-sequenced branches after sequenced branches
238-
branch
239-
]
240-
else
241-
[
242-
branch_distance(branch, default_branch),
243-
999_999, # Put non-MR branches last
244-
999,
245-
branch
246-
]
247-
end
213+
seq_mr_match_data = seq_mr_pattern.match(branch)
214+
backport_match_data = backport_pattern.match(branch)
215+
mr_match_data = mr_pattern.match(branch)
216+
217+
if seq_mr_match_data
218+
# Sort by: [branch_distance, mr_id, seq_nr, branch_name]
219+
# This ensures branches are grouped by MR and ordered by sequence within each MR
220+
[
221+
branch_distance(branch, default_branch),
222+
seq_mr_match_data[:mr_id].to_i,
223+
seq_mr_match_data[:mr_seq_nr].to_i,
224+
branch
225+
]
226+
elsif backport_match_data
227+
[
228+
branch_distance(branch, default_branch),
229+
backport_match_data[:mr_id].to_i,
230+
999, # Put backport branches after sequenced branches
231+
backport_match_data[:milestone].tr(".", "-").to_f
232+
]
233+
elsif mr_match_data
234+
[
235+
branch_distance(branch, default_branch),
236+
mr_match_data[:mr_id].to_i,
237+
999, # Put non-sequenced branches after sequenced branches
238+
branch
239+
]
240+
else
241+
[
242+
branch_distance(branch, default_branch),
243+
999_999, # Put non-MR branches last
244+
999,
245+
branch
246+
]
248247
end
248+
end
249249

250250
mr_seq_branches = {}
251251

@@ -431,10 +431,8 @@ def deleted_branch_tip_from_reflog(branch_name_prefix, descendant_branch = nil)
431431
/\bcheckout: moving from .+ to #{escaped}/
432432
]
433433

434-
reflog_cmd = %W[
435-
git reflog --format=%H\ %gs
436-
--grep-reflog=checkout.*#{branch_name_prefix}
437-
--grep-reflog=rebase.*#{branch_name_prefix}
434+
reflog_cmd = [
435+
"git", "reflog", "--format=%H %gs", "--grep-reflog=checkout.*#{branch_name_prefix}", "--grep-reflog=rebase.*#{branch_name_prefix}"
438436
]
439437

440438
IO.popen(reflog_cmd) do |io|
@@ -493,7 +491,7 @@ def rebase_all
493491
mappings = rebase_mappings
494492
.sort_by { |b| [branch_distance(b[:branch], default_branch), branch_sort_key(b)] }
495493
.to_h { |b| [b[:branch], {rebase_onto: b[:rebase_onto], fork_point: b[:fork_point]}] }
496-
rebase_all_per_capture_info(mappings)
494+
exit(1) if rebase_all_per_capture_info(mappings) == false
497495
end
498496

499497
def git_push_issue(*args)
@@ -533,7 +531,7 @@ def git_push_issue(*args)
533531

534532
puts "Pushing ".brown + branches.map(&:cyan).join(", ") + " to ".brown + active_remote_name.green + "...".brown
535533

536-
system(*%W[git push --force-with-lease #{active_remote_name}], *branches, *args)
534+
exit(1) unless system(*%W[git push --force-with-lease #{active_remote_name}], *branches, *args)
537535
end
538536

539537
def changed_branch_files(format: nil)

.shellrc/zshrc.d/functions/scripts/gitlab-helpers.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def gitlab_mr_rate(*author)
106106
GQL
107107
return if $CHILD_STATUS != 0
108108

109-
json_res = JSON.parse(res)
109+
json_res = Gitlab::Json.safe_parse(res)
110110
merge_requests = json_res.dig("data", "group", "mergeRequests")
111111
mrs +=
112112
merge_requests["nodes"]
@@ -116,7 +116,7 @@ def gitlab_mr_rate(*author)
116116
rescue
117117
$stderr.print "\n#{mr}\n"
118118
raise
119-
end
119+
end
120120

121121
total_time_to_merge = merge_requests["totalTimeToMerge"]
122122
page_info = merge_requests["pageInfo"]
@@ -173,6 +173,7 @@ def gitlab_mr_rate(*author)
173173
else
174174
puts msg.red
175175
end
176+
176177
puts "Average per MR: #{(total_time_to_merge / (60 * 60 * 24) / mrs.count).round(1)} days"
177178
puts "Total MRs merged: #{mrs.count}"
178179
puts "Best month: #{best_month.strftime("%Y-%m")} (#{best_month_mr_rate} MRs)"
@@ -206,7 +207,7 @@ def gpsup(remote, issue_iid)
206207
milestone = nil
207208
labels = []
208209
if $CHILD_STATUS == 0
209-
json_res = JSON.parse(res)
210+
json_res = Gitlab::Json.safe_parse(res)
210211
milestone = json_res.dig(*%w[data project group milestones nodes])
211212
.map { |h| h["title"] }
212213
.find { |title| title.match?(/^[0-9]+\.[0-9]+/) }
@@ -234,5 +235,5 @@ def gpsup(remote, issue_iid)
234235
SHELL
235236

236237
puts cmd
237-
system(cmd)
238+
exit(1) unless system(cmd)
238239
end

0 commit comments

Comments
 (0)