From a4b992233fbc6f8906592ed10ef5f580e2004246 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Fri, 5 Jun 2026 21:54:01 +0100 Subject: [PATCH] fix: replace raw echo with standard output helpers in git/switchtomain Prompt: Replace raw echo with output helpers in `git/switchtomain` Closes #649 --- CHANGELOG.md | 1 + git/switchtomain | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 835cb8a4..3ee2543c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release - Replace raw echo with output helpers in linux/install-fp - Replace raw echo with output helpers in git/update-preview - Replace raw echo with standard output helpers in git/update-dotnet-sdk +- Replace raw echo with standard output helpers in git/switchtomain ### Changed - GEOIP - Updated GEOIP DB from MaxMind (2026-06-03) - Replace raw echo with standard output helpers (die/info/success) in github/cancel-workflows diff --git a/git/switchtomain b/git/switchtomain index f4bf3fe4..d1a30c9c 100755 --- a/git/switchtomain +++ b/git/switchtomain @@ -1,18 +1,31 @@ #! /bin/sh + +die() { + printf '\n\033[31m✗\033[0m %s\n' "$*" >&2 + exit 1 +} + +success() { + printf '\n\033[32m✓\033[0m %s\n' "$*" +} + +info() { + printf '\n\033[32m→\033[0m %s\n' "$*" +} + find "$(pwd)"/* -name '*.git' -print | sed "s|/.git$||" | sort -u | grep -v .cache | while IFS= read -r line do - echo "$line" + info "$line" CURRENT_DIR=$line DEFAULT_BRANCH=$(git -C "$CURRENT_DIR" remote show origin | sed -n '/HEAD branch/s/.*: //p') - echo "" - echo "Retrieving $CURRENT_DIR..." + info "Retrieving $CURRENT_DIR..." git -C "$CURRENT_DIR" remote get-url origin 2>&1 git -C "$CURRENT_DIR" fetch origin 2>&1 - [ -z "$DEFAULT_BRANCH" ] && echo "**** No default branch found" - [ ! -z "$DEFAULT_BRANCH" ] && git -C "$CURRENT_DIR" checkout "$DEFAULT_BRANCH" 2>&1 - [ ! -z "$DEFAULT_BRANCH" ] && git -C "$CURRENT_DIR" fetch origin 2>&1 + [ -z "$DEFAULT_BRANCH" ] && info "No default branch found" + [ -n "$DEFAULT_BRANCH" ] && git -C "$CURRENT_DIR" checkout "$DEFAULT_BRANCH" 2>&1 + [ -n "$DEFAULT_BRANCH" ] && git -C "$CURRENT_DIR" fetch origin 2>&1 - echo " * done" + success "$CURRENT_DIR" done