From f0453abf09346456091b57f16b3ad4e994aba555 Mon Sep 17 00:00:00 2001 From: 0xheartcode <0xheartcode@gmail.com> Date: Tue, 17 Mar 2026 14:40:01 +0100 Subject: [PATCH] fix: add set -o pipefail and fix SIGPIPE in all bin scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch shebang from #!/bin/sh to #!/bin/bash and add set -o pipefail after set -e in all 20 executable bin scripts. Fix SIGPIPE-risky pipe patterns that would cause exit 141: - git log ... | sed | head -1 → git log ... | sed | head -1 wrapped in (set +o pipefail; ...) - printf '$var' | head -1 → shell parameter expansion ${var%%$'\n'*} - Remaining truncating pipes wrapped in (set +o pipefail; ...) Closes #127 --- bin/git-issue | 3 ++- bin/git-issue-comment | 3 ++- bin/git-issue-create | 3 ++- bin/git-issue-edit | 7 ++++--- bin/git-issue-export | 3 ++- bin/git-issue-export-gitea | 15 ++++++++------- bin/git-issue-export-github | 15 ++++++++------- bin/git-issue-export-gitlab | 15 ++++++++------- bin/git-issue-fsck | 3 ++- bin/git-issue-import | 3 ++- bin/git-issue-import-gitea | 13 +++++++------ bin/git-issue-import-github | 21 +++++++++++---------- bin/git-issue-import-gitlab | 13 +++++++------ bin/git-issue-init | 5 +++-- bin/git-issue-ls | 3 ++- bin/git-issue-merge | 5 +++-- bin/git-issue-search | 3 ++- bin/git-issue-show | 19 ++++++++++--------- bin/git-issue-state | 3 ++- bin/git-issue-sync | 3 ++- 20 files changed, 89 insertions(+), 69 deletions(-) diff --git a/bin/git-issue b/bin/git-issue index ef84667..4ba1cfc 100755 --- a/bin/git-issue +++ b/bin/git-issue @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # git-issue - Distributed issue tracking embedded in Git # @@ -6,6 +6,7 @@ # set -e +set -o pipefail VERSION="1.3.3" diff --git a/bin/git-issue-comment b/bin/git-issue-comment index bf821d1..d3d5980 100755 --- a/bin/git-issue-comment +++ b/bin/git-issue-comment @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-comment - Add a comment to an issue # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" diff --git a/bin/git-issue-create b/bin/git-issue-create index fe90f5a..631f674 100755 --- a/bin/git-issue-create +++ b/bin/git-issue-create @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-create - Create a new issue # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" diff --git a/bin/git-issue-edit b/bin/git-issue-edit index 85f38af..72ea804 100755 --- a/bin/git-issue-edit +++ b/bin/git-issue-edit @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-edit - Edit metadata of an existing issue # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" @@ -213,8 +214,8 @@ issue_head="$(git rev-parse "$issue_ref")" if test -n "$add_labels" || test -n "$remove_labels" then # Get current labels - current_labels="$(git log --format='%(trailers:key=Labels,valueonly)' "$issue_ref" | \ - sed '/^$/d' | head -1)" + current_labels="$(git log -1 --format='%(trailers:key=Labels,valueonly)' "$issue_ref" | \ + sed '/^$/d')" current_labels="$(printf '%s' "$current_labels" | sed 's/^[[:space:]]*//')" final_labels="$current_labels" diff --git a/bin/git-issue-export b/bin/git-issue-export index 382089b..5639007 100755 --- a/bin/git-issue-export +++ b/bin/git-issue-export @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-export - Export local issues to an external provider # set -e +set -o pipefail usage() { cat </dev/null 2>&1 @@ -395,7 +396,7 @@ $body" if test -n "$assignee_login" then assignee_info="$(resolve_user "$assignee_login")" - assignee_email="$(printf '%s' "$assignee_info" | tail -1)" + assignee_email="$(set +o pipefail; printf '%s' "$assignee_info" | tail -1)" git interpret-trailers --in-place --trailer "Assignee: $assignee_email" "$tmpfile" fi @@ -430,11 +431,11 @@ $body" comment_login="$(printf '%s' "$comments_json" | jq -r ".[$i].user.login")" comment_info="$(resolve_user "$comment_login")" - comment_name="$(printf '%s' "$comment_info" | head -1)" - comment_email="$(printf '%s' "$comment_info" | tail -1)" + comment_name="$(printf '%s\n' "${comment_info%%$'\n'*}")" + comment_email="$(set +o pipefail; printf '%s' "$comment_info" | tail -1)" # Split comment into subject (max 72 chars) and body - first_line="$(printf '%s\n' "$comment_body" | head -1)" + first_line="$(printf '%s\n' "${comment_body%%$'\n'*}")" remaining="$(printf '%s\n' "$comment_body" | tail -n +2)" if test ${#first_line} -gt 72 diff --git a/bin/git-issue-import-gitlab b/bin/git-issue-import-gitlab index 1e0b8ee..8f2804e 100755 --- a/bin/git-issue-import-gitlab +++ b/bin/git-issue-import-gitlab @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # git-issue-import-gitlab - Import issues from GitLab # @@ -6,6 +6,7 @@ # set -e +set -o pipefail usage() { cat < Example: - git issue init $(printf '%s' "$all_remotes" | head -1) + git issue init $(printf '%s\n' "${all_remotes%%$'\n'*}") EOF exit 1 fi diff --git a/bin/git-issue-ls b/bin/git-issue-ls index f5c6dfc..8e4d435 100755 --- a/bin/git-issue-ls +++ b/bin/git-issue-ls @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # git-issue-ls - List issues # @@ -7,6 +7,7 @@ # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" diff --git a/bin/git-issue-merge b/bin/git-issue-merge index ad84be2..c6ba6bf 100755 --- a/bin/git-issue-merge +++ b/bin/git-issue-merge @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-merge - Merge issues from a remote # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" @@ -145,7 +146,7 @@ resolve_scalar() { printf '%s' "$_local_val" else # Tiebreaker: lexicographically greater SHA wins (POSIX-portable) - _winner="$(printf '%s\n%s\n' "$local_head" "$remote_head" | sort | tail -1)" + _winner="$(set +o pipefail; printf '%s\n%s\n' "$local_head" "$remote_head" | sort | tail -1)" if test "$_winner" = "$local_head" then printf '%s' "$_local_val" diff --git a/bin/git-issue-search b/bin/git-issue-search index 14e56b3..c390085 100755 --- a/bin/git-issue-search +++ b/bin/git-issue-search @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # git-issue-search - Search issues by text pattern # @@ -7,6 +7,7 @@ # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" diff --git a/bin/git-issue-show b/bin/git-issue-show index 015eb2b..86c542f 100755 --- a/bin/git-issue-show +++ b/bin/git-issue-show @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-show - Show issue details and comments # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" @@ -84,7 +85,7 @@ then n_k=$((n_d - n_t - 1)) if test "$n_k" -gt 0 then - description="$(printf '%s\n' "$raw_desc" | head -n "$n_k")" + description="$(set +o pipefail; printf '%s\n' "$raw_desc" | head -n "$n_k")" fi else description="$raw_desc" @@ -92,19 +93,19 @@ then fi # Get current state -state="$(git log --format='%(trailers:key=State,valueonly)' "$issue_ref" | \ +state="$(set +o pipefail; git log --format='%(trailers:key=State,valueonly)' "$issue_ref" | \ sed '/^$/d' | head -1)" test -n "$state" || state="open" state="$(printf '%s' "$state" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" # Get other metadata from most recent trailers -labels="$(git log --format='%(trailers:key=Labels,valueonly)' "$issue_ref" | \ +labels="$(set +o pipefail; git log --format='%(trailers:key=Labels,valueonly)' "$issue_ref" | \ sed '/^$/d' | head -1)" -assignee="$(git log --format='%(trailers:key=Assignee,valueonly)' "$issue_ref" | \ +assignee="$(set +o pipefail; git log --format='%(trailers:key=Assignee,valueonly)' "$issue_ref" | \ head -1)" -priority="$(git log --format='%(trailers:key=Priority,valueonly)' "$issue_ref" | \ +priority="$(set +o pipefail; git log --format='%(trailers:key=Priority,valueonly)' "$issue_ref" | \ head -1)" -milestone="$(git log --format='%(trailers:key=Milestone,valueonly)' "$issue_ref" | \ +milestone="$(set +o pipefail; git log --format='%(trailers:key=Milestone,valueonly)' "$issue_ref" | \ head -1)" # Get author and date @@ -160,7 +161,7 @@ then c_subject="$(git log -1 --format='%s' "$commit")" c_body="$(git log -1 --format='%b' "$commit")" c_state="$(git log -1 --format='%(trailers:key=State,valueonly)' "$commit" | \ - sed '/^$/d' | head -1)" + sed '/^$/d')" printf '\n %s (%s):\n' "$c_author" "$c_date" @@ -183,7 +184,7 @@ then c_nk=$((c_nd - c_nt - 1)) if test "$c_nk" -gt 0 then - printf '%s\n' "$c_body" | head -n "$c_nk" | sed '/^$/d' | sed 's/^/ /' + (set +o pipefail; printf '%s\n' "$c_body" | head -n "$c_nk") | sed '/^$/d' | sed 's/^/ /' fi else printf '%s\n' "$c_body" | sed '/^$/d' | sed 's/^/ /' diff --git a/bin/git-issue-state b/bin/git-issue-state index 69627cb..27ae57c 100755 --- a/bin/git-issue-state +++ b/bin/git-issue-state @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-state - Change the state of an issue # set -e +set -o pipefail . "$(dirname "$0")/git-issue-lib" diff --git a/bin/git-issue-sync b/bin/git-issue-sync index bb0ee1f..2b732ef 100755 --- a/bin/git-issue-sync +++ b/bin/git-issue-sync @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash # # git-issue-sync - Two-way sync with an external provider (import + export) # set -e +set -o pipefail usage() { cat <