From 1e44c449e96679c9ded52a9df730a6fc39d2b03f Mon Sep 17 00:00:00 2001 From: IVA2K Date: Thu, 18 Jul 2024 17:03:40 -0700 Subject: [PATCH 1/4] More thorough logging of commands in scripts/git-*.sh --- scripts/git-merge_main-to-all-ui.sh | 124 +++++++++++++++++++++------- scripts/git-run-all-in-branches.sh | 39 ++++----- 2 files changed, 110 insertions(+), 53 deletions(-) diff --git a/scripts/git-merge_main-to-all-ui.sh b/scripts/git-merge_main-to-all-ui.sh index 3ad18208..88ed9c0b 100644 --- a/scripts/git-merge_main-to-all-ui.sh +++ b/scripts/git-merge_main-to-all-ui.sh @@ -66,18 +66,18 @@ function clear_state() { } function save_state() { [ "$DEBUG" -ne 0 ] && echo "DEBUG: save_state() saving to file \"$STATE_FILE\"." - declare -p outputs > "$STATE_FILE" - declare -p errors >> "$STATE_FILE" - declare -p tms_real >> "$STATE_FILE" - declare -p branches_done >> "$STATE_FILE" - # declare -p TARGET_BRANCHES >> "$STATE_FILE" + { declare -p outputs + declare -p errors + declare -p tms_real + declare -p branches_done + # declare -p TARGET_BRANCHES + } > "$STATE_FILE" [ "$DEBUG" -ne 0 ] && echo "DEBUG: save_state() DONE saving to file \"$STATE_FILE\"." } function exit_save_state() { rc="$1" - [ "$DEBUG" -ne 0 ] && echo "DEBUG: exit_save_state($rc) saving to file \"$STATE_FILE\"." save_state - echo + [ "$DEBUG" -ne 0 ] && echo "DEBUG: exit_save_state($rc)." exit $((rc)) } function load_state() { @@ -201,6 +201,64 @@ function decolor() { echo -e "$input" | sed 's/\x1B\[\([0-9]\{1,2\}\(;[0-9]\{1,2\}\)\?\)\?[mGK]//g' } +function git_push_with_log() { + local branch="$1" + local log_file + log_file="log.merge.$branch.push_$(date +%Y%m%d-%H%M%S).txt" + [ "$DEBUG" -ne 0 ] && echo "DEBUG: git_push_with_log() branch=$branch log_file=$log_file" + + { echo "Push log for branch: $branch" + echo "Date: $(date +%Y%m%d-%H%M%S)" + echo "" + } > "$log_file" + + # Get the range of commits being pushed + local range + range=$(git rev-parse "$branch@{push}..$branch") + + local local_sha + local remote_sha + local_sha=$(git rev-parse "$branch") + remote_sha=$(git rev-parse "origin/$branch" 2>/dev/null || echo "") + + if [ -z "$remote_sha" ]; then + echo "New branch, comparing with initial commit" >> "$log_file" + range="$(git rev-list --max-parents=0 HEAD)...$local_sha" + else + range="$remote_sha...$local_sha" + fi + + # List of modified files + { echo "Modified files:" + git diff --name-status "$range" + echo "" + } >> "$log_file" + + # List of commits being pushed + { echo "Commits being pushed:" + git log --oneline "$range" + echo "" + } >> "$log_file" + + # List of merged branches + { echo "Merged branches:" + git branch --merged "$branch" | grep -v "^\*" + echo "" + } >> "$log_file" + + # Additional information + { echo "Additional information:" + echo "Current user: $(git config user.name)" + echo "Current email: $(git config user.email)" + echo "Remote URL: $(git remote get-url origin)" + } >> "$log_file" + + # Perform the actual push + git push origin "$branch" + + echo "Push log saved to $log_file" +} + function merge_to_one() { is_continue="$1" i="$2" @@ -225,7 +283,7 @@ function merge_to_one() { echo | tee -a "$LOGFILE" # Switch to the target branch # Checkout target branch - if ! output=$(git checkout "$TARGET_BRANCH") ; then + if ! output=$(git checkout "$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE") ; then echo | tee -a "$LOGFILE" echo "Error checking out branch \"$TARGET_BRANCH\"." | tee -a "$LOGFILE" outputs[i]="Error checking out branch" @@ -235,8 +293,9 @@ function merge_to_one() { # Merge changes from the source branch, but not commit # if ! git merge "$SOURCE_BRANCH" --no-edit ; then - git merge "$SOURCE_BRANCH" --no-commit - res=$? + git merge "$SOURCE_BRANCH" --no-commit 2>&1 | tee -a "$LOGFILE" + # res=$? ;# won't work due to ` | tee ...` + res=${PIPESTATUS[0]} if [ "$res" -ne 0 ] ; then echo "Merge conflict(s) detected in \"$TARGET_BRANCH\" branch." | tee -a "$LOGFILE" fi @@ -261,8 +320,9 @@ function merge_to_one() { if git diff --name-only --diff-filter=U | grep -q "pnpm-lock.yaml"; then echo " Merge conflict(s) in \"pnpm-lock.yaml\", recreating..." | tee -a "$LOGFILE" - ( "${COMMAND_MERGE_LOCKFILE[@]}" ) - error=$? + ( "${COMMAND_MERGE_LOCKFILE[@]}" ) | tee -a "$LOGFILE" + # error=$? ;# won't work due to ` | tee ...` + error=${PIPESTATUS[0]} echo " DONE Recreating \"pnpm-lock.yaml\", error=$error." | tee -a "$LOGFILE" pkg_updated=0 fi @@ -279,25 +339,28 @@ function merge_to_one() { exit_save_state 1 else echo " No unresolved Merge conflicts left, continuing..." | tee -a "$LOGFILE" - git commit --no-edit + git commit --no-edit 2>&1 | tee -a "$LOGFILE" outputs[i]="Merge conflicts resolved" errors[i]=0 fi else - git commit --no-edit + echo " No Merge conflicts, continuing..." | tee -a "$LOGFILE" + # No "-m" as merge sets up a commit message for us to use. + git commit --no-edit 2>&1 | tee -a "$LOGFILE" fi if [ "$pkg_updated" -ne 0 ] ; then echo " Changes to \"package.json\" file were merged, updating \"pnpm-lock.yaml\"..." | tee -a "$LOGFILE" outputs[i]="${outputs[i]}, package.json merged and lockfile updated" - ( "${COMMAND_UPDATE_LOCKFILE[@]}" ) - error=$? + ( "${COMMAND_UPDATE_LOCKFILE[@]}" ) | tee -a "$LOGFILE" + # error=$? ;# won't work due to ` | tee ...` + error=${PIPESTATUS[0]} echo " DONE Updating \"pnpm-lock.yaml\", error=$error." | tee -a "$LOGFILE" fi # Push the changes to the remote repository - git push origin "$TARGET_BRANCH" + git_push_with_log "$TARGET_BRANCH" | tee -a "$LOGFILE" branches_done[i]="$TARGET_BRANCH" echo | tee -a "$LOGFILE" @@ -366,13 +429,13 @@ function merge_to_all() { done # Fetch the latest changes from the remote repository - git fetch origin + git fetch origin 2>&1 | tee -a "$LOGFILE" # Switch to the source branch - git checkout "$SOURCE_BRANCH" + git checkout "$SOURCE_BRANCH" 2>&1 | tee -a "$LOGFILE" # Pull the latest changes from the source branch - git pull origin "$SOURCE_BRANCH" + git pull origin "$SOURCE_BRANCH" 2>&1 | tee -a "$LOGFILE" # Loop through each target branch and execute one for i in $(seq "$start_i" $((${#TARGET_BRANCHES[@]}-1))); do @@ -380,7 +443,7 @@ function merge_to_all() { echo " run time=${tms_real[$i]}s" | tee -a "$LOGFILE" ;# | tee -a "$LOGFILE_I" done - git checkout "$SOURCE_BRANCH" + git checkout "$SOURCE_BRANCH" 2>&1 | tee -a "$LOGFILE" } function print_summary() { @@ -389,10 +452,9 @@ function print_summary() { pass_cnt=0 total_cnt=0 total_time=0 - FORMAT="| %-20s | %6s | %-100s |" - # FORMAT="| %-20s | %6s | %-30s | %9s | %-100s |" - HEAD=$(printf "$FORMAT" "Branch" "Error" "Output") - LINE=$(printf "$FORMAT" "" "") + FORMAT="| %-20s | %6s | %9s | %-100s |" + HEAD=$(printf "$FORMAT" "Branch" "Error" "Time (s)" "Output") + LINE=$(printf "$FORMAT" "" "" "" "") LINE="${LINE// /-}" echo | tee -a "$LOGFILE" echo "${SEP1}" | tee -a "$LOGFILE" @@ -413,15 +475,13 @@ function print_summary() { color_red=1 errors_cnt=$((errors_cnt+1)) fi - total_time=$(awk "BEGIN {print ($total_time+${tms_real[$i]})}") + total_time=$(awk "BEGIN {print ($total_time+0${tms_real[$i]})}") [ "$color_red" -ne 0 ] && echo -n -e "\033[31m" - printf "$FORMAT\n" "$TARGET_BRANCH" "$error" "${output:0:100}" | tee -a "$LOGFILE" - # printf "$FORMAT\n" "$TARGET_BRANCH" "$error" "$LOGFILE_I" "${tms_real[$i]}" "${output:0:100}" | tee -a "$LOGFILE" + printf "$FORMAT\n" "$TARGET_BRANCH" "$error" "${tms_real[$i]}" "${output:0:100}" | tee -a "$LOGFILE" [ "$color_red" -ne 0 ] && echo -n -e "\033[36m" done echo "$LINE" | tee -a "$LOGFILE" - printf "$FORMAT\n" "Total:" "$errors_cnt" "" | tee -a "$LOGFILE" - # printf "$FORMAT\n" "Total:" "$errors_cnt" "$total_cnt" "$total_time" "" | tee -a "$LOGFILE" + printf "$FORMAT\n" "Total:" "$errors_cnt" "$total_time" "" | tee -a "$LOGFILE" echo "$LINE" | tee -a "$LOGFILE" echo | tee -a "$LOGFILE" total_time_m=$(awk "BEGIN {print ($total_time / 60)}") @@ -432,7 +492,6 @@ function print_summary() { echo | tee -a "$LOGFILE" echo "DONE Merging branch \"$SOURCE_BRANCH\" into $total_cnt target branches, $pass_cnt passed, $errors_cnt error(s), $total_time_h:$total_time_m:$total_time_s elapsed time." | tee -a "$LOGFILE" - # echo "DONE command \"${COMMAND[*]}\" in $total_cnt target branches, $pass_cnt passed, $errors_cnt error(s), $total_time_h:$total_time_m:$total_time_s elapsed time." | tee -a "$LOGFILE" echo | tee -a "$LOGFILE" return $result @@ -448,10 +507,11 @@ main() { fi load_state - echo "" >"$LOGFILE" if [ "$continue_merge" -ne 0 ]; then + # Previous $LOGFILE is continued continue_merge_to_all "$@" else + echo "" >"$LOGFILE" ;# Clear Previous $LOGFILE merge_to_all 0 "$@" fi diff --git a/scripts/git-run-all-in-branches.sh b/scripts/git-run-all-in-branches.sh index d61b3b8b..5581ffef 100644 --- a/scripts/git-run-all-in-branches.sh +++ b/scripts/git-run-all-in-branches.sh @@ -79,18 +79,18 @@ function clear_state() { } function save_state() { [ "$DEBUG" -ne 0 ] && echo "DEBUG: save_state() saving to file \"$STATE_FILE\"." - declare -p outputs > "$STATE_FILE" - declare -p errors >> "$STATE_FILE" - declare -p tms_real >> "$STATE_FILE" - declare -p branches_done >> "$STATE_FILE" - # declare -p TARGET_BRANCHES >> "$STATE_FILE" + { declare -p outputs + declare -p errors + declare -p tms_real + declare -p branches_done + # declare -p TARGET_BRANCHES + } > "$STATE_FILE" [ "$DEBUG" -ne 0 ] && echo "DEBUG: save_state() DONE saving to file \"$STATE_FILE\"." } function exit_save_state() { rc="$1" - [ "$DEBUG" -ne 0 ] && echo "DEBUG: exit_save_state($rc) saving to file \"$STATE_FILE\"." save_state - echo + [ "$DEBUG" -ne 0 ] && echo "DEBUG: exit_save_state($rc)." exit $((rc)) } function load_state() { @@ -164,11 +164,12 @@ function run_one() { LOGFILE_I="$LOGFILE.$TARGET_BRANCH" echo "${SEP2}" | tee -a "$LOGFILE" [ "$DEBUG" -ne 0 ] && echo "DEBUG: run_one() i=$i TARGET_BRANCH=$TARGET_BRANCH LOGFILE_I=$LOGFILE_I" - save_state + save_state ;# checkpoint # Switch to the target branch echo "CHECKOUT $TARGET_BRANCH" | tee -a "$LOGFILE" | tee "$LOGFILE_I" - git checkout "$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) + # git checkout "$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) + git checkout "$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" echo "PREP $TARGET_BRANCH" | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" "${COMMAND_PREP[@]}" >>"$LOGFILE_I" 2>&1 @@ -184,14 +185,12 @@ function run_one() { return else echo "PREP ERROR $prep_error in branch \"$TARGET_BRANCH\", cleaning up and continuing." | (tee -a "$LOGFILE" >&2) - git reset --hard "origin/$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) + # git reset --hard "origin/$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) + git reset --hard "origin/$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" fi fi echo "BEGIN command \"${COMMAND[*]}\" in branch \"$TARGET_BRANCH\"..." | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" - # output=$("${COMMAND[@]}" >>"$LOGFILE_I" 2>&1) - # tm "${COMMAND[@]}" >>"$LOGFILE_I" 2>&1 - # output=$(tm "${COMMAND[@]}" >>"$LOGFILE_I" 2>&1) # Run command "${COMMAND[@]}" >>"$LOGFILE_I" 2>&1 @@ -207,7 +206,8 @@ function run_one() { return else echo "ERROR $error in branch \"$TARGET_BRANCH\", cleaning up and continuing." | tee -a "$LOGFILE" - git reset --hard "origin/$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) + # git reset --hard "origin/$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) + git reset --hard "origin/$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" fi fi @@ -238,12 +238,9 @@ function run_all() { outputs[i]="\033[31m(did not run)\033[36m" tms_real[i]=0 done - # errors[0]=0 ;# for DEBUG only - # errors[1]=1 ;# for DEBUG only - # echo "" >"$LOGFILE" # Fetch the latest changes from the remote repository - git fetch origin + git fetch origin 2>&1 | tee -a "$LOGFILE" # Loop through each target branch and execute one for i in $(seq "$start_i" $((${#TARGET_BRANCHES[@]}-1))); do @@ -252,7 +249,7 @@ function run_all() { echo " run time=${tms_real[$i]}s" | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" done - git checkout "$SOURCE_BRANCH" + git checkout "$SOURCE_BRANCH" 2>&1 | tee -a "$LOGFILE" } function print_summary() { @@ -263,7 +260,7 @@ function print_summary() { total_time=0 FORMAT="| %-20s | %6s | %-30s | %9s | %-100s |" HEAD=$(printf "$FORMAT" "Branch" "Error" "Log File" "Time (s)" "Output") - LINE=$(printf "$FORMAT" "" "" "" "") + LINE=$(printf "$FORMAT" "" "" "" "" "") LINE="${LINE// /-}" echo | tee -a "$LOGFILE" echo "${SEP1}" | tee -a "$LOGFILE" @@ -285,7 +282,7 @@ function print_summary() { color_red=1 errors_cnt=$((errors_cnt+1)) fi - total_time=$(awk "BEGIN {print ($total_time+${tms_real[$i]})}") + total_time=$(awk "BEGIN {print ($total_time+0${tms_real[$i]})}") [ "$color_red" -ne 0 ] && echo -n -e "\033[31m" printf "$FORMAT\n" "$TARGET_BRANCH" "$error" "$LOGFILE_I" "${tms_real[$i]}" "${output:0:102}" | tee -a "$LOGFILE" [ "$color_red" -ne 0 ] && echo -n -e "\033[39m" From 0203df61c87508bc5b32e738106fb2cd0dd0378e Mon Sep 17 00:00:00 2001 From: IVA2K Date: Thu, 18 Jul 2024 17:17:27 -0700 Subject: [PATCH 2/4] Lint --- pnpm-lock.yaml | 2 +- src/lib/utils/test.svelte.ts | 102 +++++++++++++++++------------------ 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7e56c7e..73156e3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -139,7 +139,7 @@ importers: specifier: ^0.8.0 version: 0.8.0(eslint@9.7.0)(typescript@5.5.3) eslint-plugin-svelte: - specifier: ^2.36.0 + specifier: ^2.42.0 version: 2.42.0(eslint@9.7.0)(svelte@5.0.0-next.190)(ts-node@10.9.2(@types/node@20.14.11)(typescript@5.5.3)) eslint-plugin-vitest: specifier: ^0.5.4 diff --git a/src/lib/utils/test.svelte.ts b/src/lib/utils/test.svelte.ts index c48a1495..d1124a32 100644 --- a/src/lib/utils/test.svelte.ts +++ b/src/lib/utils/test.svelte.ts @@ -1,51 +1,51 @@ -/** - * Run a function inside Svelte's effect context - * (From ) - * Usage: - * ```js - * import { describe, expect, expectTypeOf, it, vi } from 'vitest'; - * import { withEffect } from '../../utils/test.svelte.js'; - * import { useFloating, type FloatingContext } from './index.svelte.js'; - * import { - * offset, - * type Middleware, - * type MiddlewareData, - * type Placement, - * type Strategy, - * } from '@floating-ui/dom'; - * import { useId } from '../useId/index.js'; - * - * function createElements(): { reference: HTMLElement; floating: HTMLElement } { - * const reference = document.createElement('div'); - * const floating = document.createElement('div'); - * reference.id = useId(); - * floating.id = useId(); - * return { reference, floating }; - * } - * - * describe('useFloating', () => { - * describe('elements', () => { - * it( - * 'can be set', - * withEffect(() => { - * const elements = createElements(); - * const floating = useFloating({ elements }); - * expect(floating.elements).toEqual(elements); - * }), - * ); - * ... - * }); - * }); - * ``` - */ -export function withEffect(fn: () => void) { - return async () => { - let promise; - const cleanup = $effect.root(() => (promise = fn())); - try { - return await promise; - } finally { - cleanup(); - } - }; -} +/** + * Run a function inside Svelte's effect context + * (From ) + * Usage: + * ```js + * import { describe, expect, expectTypeOf, it, vi } from 'vitest'; + * import { withEffect } from '../../utils/test.svelte.js'; + * import { useFloating, type FloatingContext } from './index.svelte.js'; + * import { + * offset, + * type Middleware, + * type MiddlewareData, + * type Placement, + * type Strategy, + * } from '@floating-ui/dom'; + * import { useId } from '../useId/index.js'; + * + * function createElements(): { reference: HTMLElement; floating: HTMLElement } { + * const reference = document.createElement('div'); + * const floating = document.createElement('div'); + * reference.id = useId(); + * floating.id = useId(); + * return { reference, floating }; + * } + * + * describe('useFloating', () => { + * describe('elements', () => { + * it( + * 'can be set', + * withEffect(() => { + * const elements = createElements(); + * const floating = useFloating({ elements }); + * expect(floating.elements).toEqual(elements); + * }), + * ); + * ... + * }); + * }); + * ``` + */ +export function withEffect(fn: () => void) { + return async () => { + let promise; + const cleanup = $effect.root(() => (promise = fn())); + try { + return await promise; + } finally { + cleanup(); + } + }; +} From 60103bb120c9a88718a6768e717ba8492b798744 Mon Sep 17 00:00:00 2001 From: IVA2K Date: Thu, 18 Jul 2024 17:39:32 -0700 Subject: [PATCH 3/4] .gitignore .logs/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f235385f..4f02a58e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ vite.config.js.timestamp-* vite.config.ts.timestamp-* # Generated +.logs/ .types log.* *.log From a4a17f72290f32cec2f6b2f63880c5ddcc8a7bd9 Mon Sep 17 00:00:00 2001 From: IVA2K Date: Thu, 18 Jul 2024 17:52:15 -0700 Subject: [PATCH 4/4] Move logs to .lgs/ * More error checks on git commands --- scripts/git-merge_main-to-all-ui.sh | 30 +++++++++++++++++----- scripts/git-run-all-in-branches.sh | 40 +++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/scripts/git-merge_main-to-all-ui.sh b/scripts/git-merge_main-to-all-ui.sh index 88ed9c0b..07a6fce9 100644 --- a/scripts/git-merge_main-to-all-ui.sh +++ b/scripts/git-merge_main-to-all-ui.sh @@ -8,8 +8,9 @@ git config user.name "IVA2K" DEBUG=0 # DEBUG=1 -STATE_FILE="./.git-merge-all.state.local" -STATE_FILE_BACKUP="./.git-merge-all.backup.local" + +STATE_FILE=".logs/.git-merge-all.state.local" +STATE_FILE_BACKUP=".logs/.git-merge-all.backup.local" function rebuild_lockfile() { git checkout HEAD -- pnpm-lock.yaml && pnpm install && git add pnpm-lock.yaml @@ -21,7 +22,7 @@ function rebuild_lockfile_and_commit() { COMMAND_MERGE_LOCKFILE=( "rebuild_lockfile" ) COMMAND_UPDATE_LOCKFILE=( "rebuild_lockfile_and_commit" ) -LOGFILE=log.merge-all +LOGFILE=".logs/log.merge-all" SOURCE_BRANCH="main" @@ -203,8 +204,8 @@ function decolor() { function git_push_with_log() { local branch="$1" - local log_file - log_file="log.merge.$branch.push_$(date +%Y%m%d-%H%M%S).txt" + local log_file="$2" + mkdir -p "$(dirname "$log_file")" >/dev/null [ "$DEBUG" -ne 0 ] && echo "DEBUG: git_push_with_log() branch=$branch log_file=$log_file" { echo "Push log for branch: $branch" @@ -255,8 +256,9 @@ function git_push_with_log() { # Perform the actual push git push origin "$branch" - + rc="$?" echo "Push log saved to $log_file" + return "$rc" } function merge_to_one() { @@ -340,6 +342,13 @@ function merge_to_one() { else echo " No unresolved Merge conflicts left, continuing..." | tee -a "$LOGFILE" git commit --no-edit 2>&1 | tee -a "$LOGFILE" + # res=$? ;# won't work due to ` | tee ...` + res=${PIPESTATUS[0]} + if [ "$res" -ne 0 ] ; then + echo "Error $res in commit to \"$TARGET_BRANCH\" branch." | tee -a "$LOGFILE" + errors[i]="$res" + exit_save_state "$res" + fi outputs[i]="Merge conflicts resolved" errors[i]=0 fi @@ -360,7 +369,13 @@ function merge_to_one() { fi # Push the changes to the remote repository - git_push_with_log "$TARGET_BRANCH" | tee -a "$LOGFILE" + git_push_with_log "$TARGET_BRANCH" ".logs/log.merge{${SOURCE_BRANCH}}-{${TARGET_BRANCH}}.$(date +%Y%m%d-%H%M%S).txt" | tee -a "$LOGFILE" + res=${PIPESTATUS[0]} + if [ "$res" -ne 0 ] ; then + echo "Error $res in push to \"$TARGET_BRANCH\" branch." | tee -a "$LOGFILE" + errors[i]="$res" + exit_save_state "$res" + fi branches_done[i]="$TARGET_BRANCH" echo | tee -a "$LOGFILE" @@ -507,6 +522,7 @@ main() { fi load_state + mkdir -p "$(dirname "$LOGFILE")" >/dev/null if [ "$continue_merge" -ne 0 ]; then # Previous $LOGFILE is continued continue_merge_to_all "$@" diff --git a/scripts/git-run-all-in-branches.sh b/scripts/git-run-all-in-branches.sh index 5581ffef..9a3424a0 100644 --- a/scripts/git-run-all-in-branches.sh +++ b/scripts/git-run-all-in-branches.sh @@ -8,8 +8,9 @@ git config user.name "IVA2K" DEBUG=0 # DEBUG=1 -STATE_FILE="./.git-run-all.state.local" -STATE_FILE_BACKUP="./.git-run-all.backup.local" + +STATE_FILE=".logs/.git-run-all.state.local" +STATE_FILE_BACKUP=".logs/.git-run-all.backup.local" function no_prep() { echo > /dev/null @@ -21,13 +22,13 @@ function do_prep() { COMMAND_PREP=( no_prep ) COMMAND=(pnpm run all) -LOGFILE=log.runallall +LOGFILE=".logs/log.runallall" # COMMAND_PREP=( do_prep ) # COMMAND=(pnpm run check) -# LOGFILE=log.runcheck +# LOGFILE=".logs/log.runcheck" # COMMAND=(pnpm run lint) -# LOGFILE=log.runlint +# LOGFILE=".logs/log.runlint" STOP_ON_ERROR=0 @@ -170,6 +171,13 @@ function run_one() { echo "CHECKOUT $TARGET_BRANCH" | tee -a "$LOGFILE" | tee "$LOGFILE_I" # git checkout "$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) git checkout "$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" + # res=$? ;# won't work due to ` | tee ...` + res=${PIPESTATUS[0]} + if [ "$res" -ne 0 ] ; then + echo "Error $res in checkout to \"$TARGET_BRANCH\" branch." | tee -a "$LOGFILE" + errors[i]="$res" + exit_save_state "$res" + fi echo "PREP $TARGET_BRANCH" | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" "${COMMAND_PREP[@]}" >>"$LOGFILE_I" 2>&1 @@ -187,6 +195,13 @@ function run_one() { echo "PREP ERROR $prep_error in branch \"$TARGET_BRANCH\", cleaning up and continuing." | (tee -a "$LOGFILE" >&2) # git reset --hard "origin/$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) git reset --hard "origin/$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" + # res=$? ;# won't work due to ` | tee ...` + res=${PIPESTATUS[0]} + if [ "$res" -ne 0 ] ; then + echo "Error $res in checkout to \"$TARGET_BRANCH\" branch." | tee -a "$LOGFILE" + errors[i]="$res" + exit_save_state "$res" + fi fi fi @@ -208,6 +223,13 @@ function run_one() { echo "ERROR $error in branch \"$TARGET_BRANCH\", cleaning up and continuing." | tee -a "$LOGFILE" # git reset --hard "origin/$TARGET_BRANCH" 1> >(tee -a "$LOGFILE_I") 2> >(tee -a "$LOGFILE_I" >&2) git reset --hard "origin/$TARGET_BRANCH" 2>&1 | tee -a "$LOGFILE" | tee -a "$LOGFILE_I" + # res=$? ;# won't work due to ` | tee ...` + res=${PIPESTATUS[0]} + if [ "$res" -ne 0 ] ; then + echo "Error $res in resetting \"$TARGET_BRANCH\" branch." | tee -a "$LOGFILE" + errors[i]="$res" + exit_save_state "$res" + fi fi fi @@ -241,6 +263,12 @@ function run_all() { # Fetch the latest changes from the remote repository git fetch origin 2>&1 | tee -a "$LOGFILE" + # res=$? ;# won't work due to ` | tee ...` + res=${PIPESTATUS[0]} + if [ "$res" -ne 0 ] ; then + echo "Error $res in git fetch." | tee -a "$LOGFILE" + exit_save_state "$res" + fi # Loop through each target branch and execute one for i in $(seq "$start_i" $((${#TARGET_BRANCHES[@]}-1))); do @@ -250,6 +278,7 @@ function run_all() { done git checkout "$SOURCE_BRANCH" 2>&1 | tee -a "$LOGFILE" + # Ignore errors } function print_summary() { @@ -312,6 +341,7 @@ main() { fi load_state + mkdir -p "$(dirname "$LOGFILE")" >/dev/null echo "" >"$LOGFILE" run_all 0 "$@" print_summary