Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/gitwork
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,11 @@ fi

previous='null'
if [[ -n $output && -r $output ]]; then
previous=$(jq -c . "$output" 2>/dev/null || echo 'null')
if prev_val=$(jq -c -s 'if length == 1 and (.[0] | type == "object") then .[0] else empty end' "$output" 2>/dev/null) && [[ -n $prev_val ]]; then
previous="$prev_val"
elif [[ -s $output ]]; then
echo "gitwork: warning: previous overview at $output is invalid JSON; ignoring" >&2
fi
fi

document=$(jqm -n \
Expand Down
7 changes: 7 additions & 0 deletions tests/collector-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ run_dead -output "$out" >/dev/null
assert_eq "0" "$(jq -e . "$out" >/dev/null 2>&1; echo $?)" "a repeat run leaves valid JSON"
assert_eq "3" "$(jq -r .schemaVersion "$out")" "a repeat run keeps the schema version"

# A corrupt previous document does not abort the run and self-heals
printf '{"schemaVersion": 3, "updatedAt": "2026-01-01T00:00:00Z", "providers": []}}\n' >"$out"
run_dead -output "$out" >/dev/null
assert_eq "0" "$(jq -e . "$out" >/dev/null 2>&1; echo $?)" "a corrupt previous file is replaced with valid JSON"
assert_eq "3" "$(jq -r .schemaVersion "$out")" "self-healed run keeps the schema version"
assert_contains "$(cat "$work/stderr")" "gitwork: warning" "a corrupt previous file emits a warning"

# --- formatting ------------------------------------------------------------

assert_eq "1" "$(run_dead -pretty false | wc -l)" "compact output is one line"
Expand Down