Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release
- check: use mapfile array for file collection to handle filenames containing spaces correctly
- check: guard against empty file list before checking — prevents false-positive success when no scripts are found
- git/ignore-changelog: skip push hooks when pushing to target repositories
- git/fetch and git/switchtomain now warn and skip a repo on error instead of aborting the whole run, so remaining repos still get processed.
### Changed
- Replace raw echo with standard output helpers (die/info/success) in github/cancel-workflows
- Replace raw echo with standard output helpers (die/info/success) in git/update-repos-personal
Expand Down
30 changes: 19 additions & 11 deletions git/fetch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ success() {
printf '\n\033[32m✓\033[0m %s\n' "$*"
}

warn() {
printf '\n\033[33m⚠\033[0m %s\n' "$*" >&2
}

info() {
printf '\n\033[32m→\033[0m %s\n' "$*"
}
Expand Down Expand Up @@ -49,18 +53,18 @@ do
else
git -C "$CURRENT_DIR" config --local --unset core.hookspath 2>/dev/null || true
fi
git -C "$CURRENT_DIR" remote get-url origin 2>&1 || die "Could not determine origin for ${CURRENT_DIR}"
git -C "$CURRENT_DIR" fetch --prune --prune-tags 2>&1 || die "Could not fetch ${CURRENT_DIR}"
git -C "$CURRENT_DIR" remote update origin --prune 2>&1 || die "Could not update remote refs for ${CURRENT_DIR}"
git -C "$CURRENT_DIR" remote get-url origin 2>&1 || { warn "Could not determine origin for ${CURRENT_DIR}"; continue; }
git -C "$CURRENT_DIR" fetch --prune --prune-tags 2>&1 || { warn "Could not fetch ${CURRENT_DIR}"; continue; }
git -C "$CURRENT_DIR" remote update origin --prune 2>&1 || { warn "Could not update remote refs for ${CURRENT_DIR}"; continue; }

REPO_STATUS=$(git -C "$CURRENT_DIR" status --porcelain 2>&1) || die "Could not read status for ${CURRENT_DIR}"
REPO_STATUS=$(git -C "$CURRENT_DIR" status --porcelain 2>&1) || { warn "Could not read status for ${CURRENT_DIR}"; continue; }

if [ -z "$REPO_STATUS" ]
then
if git -C "$CURRENT_DIR" rev-parse --verify '@{upstream}' > /dev/null 2>&1
then
info "No pending changes in working folder. Rebasing..."
git -C "$CURRENT_DIR" rebase 2>&1 || die "Could not rebase ${CURRENT_DIR}"
git -C "$CURRENT_DIR" rebase 2>&1 || warn "Could not rebase ${CURRENT_DIR}"
git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1
else
info "No valid upstream for current branch. Skipping rebase."
Expand All @@ -71,7 +75,7 @@ do

if [ "$SWITCH_TO_MAIN" = "1" ]
then
CURRENT_BRANCH=$(git -C "$CURRENT_DIR" rev-parse --abbrev-ref HEAD 2>&1) || die "Could not determine current branch for ${CURRENT_DIR}"
CURRENT_BRANCH=$(git -C "$CURRENT_DIR" rev-parse --abbrev-ref HEAD 2>&1) || { warn "Could not determine current branch for ${CURRENT_DIR}"; continue; }
DEFAULT_BRANCH=$(git -C "$CURRENT_DIR" symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/origin/||')

if [ -z "$DEFAULT_BRANCH" ]
Expand All @@ -84,13 +88,17 @@ do
if [ -z "$REPO_STATUS" ]
then
info "Switching to ${DEFAULT_BRANCH} branch..."
git -C "$CURRENT_DIR" checkout "$DEFAULT_BRANCH" 2>&1 || die "Could not switch to ${DEFAULT_BRANCH} in ${CURRENT_DIR}"
if git -C "$CURRENT_DIR" rev-parse --verify '@{upstream}' > /dev/null 2>&1
if git -C "$CURRENT_DIR" checkout "$DEFAULT_BRANCH" 2>&1
then
git -C "$CURRENT_DIR" rebase 2>&1 || die "Could not rebase ${DEFAULT_BRANCH} in ${CURRENT_DIR}"
git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1
if git -C "$CURRENT_DIR" rev-parse --verify '@{upstream}' > /dev/null 2>&1
then
git -C "$CURRENT_DIR" rebase 2>&1 || warn "Could not rebase ${DEFAULT_BRANCH} in ${CURRENT_DIR}"
git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1
else
info "No valid upstream for ${DEFAULT_BRANCH}. Skipping rebase."
fi
else
info "No valid upstream for ${DEFAULT_BRANCH}. Skipping rebase."
warn "Could not switch to ${DEFAULT_BRANCH} in ${CURRENT_DIR}"
fi
else
info "Pending changes in working folder. Skipping switch to ${DEFAULT_BRANCH}."
Expand Down
25 changes: 19 additions & 6 deletions git/switchtomain
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ success() {
printf '\n\033[32m✓\033[0m %s\n' "$*"
}

warn() {
printf '\n\033[33m⚠\033[0m %s\n' "$*" >&2
}

info() {
printf '\n\033[32m→\033[0m %s\n' "$*"
}
Expand All @@ -18,14 +22,23 @@ do
info "$line"
CURRENT_DIR=$line

DEFAULT_BRANCH=$(git -C "$CURRENT_DIR" remote show origin | sed -n '/HEAD branch/s/.*: //p')
info "Retrieving $CURRENT_DIR..."
git -C "$CURRENT_DIR" remote get-url origin 2>&1
git -C "$CURRENT_DIR" fetch origin 2>&1
git -C "$CURRENT_DIR" remote get-url origin 2>&1 || { warn "Could not determine origin for ${CURRENT_DIR}"; continue; }
git -C "$CURRENT_DIR" fetch origin 2>&1 || { warn "Could not fetch ${CURRENT_DIR}"; continue; }

DEFAULT_BRANCH=$(git -C "$CURRENT_DIR" remote show origin | sed -n '/HEAD branch/s/.*: //p')

[ -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
if [ -z "$DEFAULT_BRANCH" ]
then
info "No default branch found"
else
if git -C "$CURRENT_DIR" checkout "$DEFAULT_BRANCH" 2>&1
then
git -C "$CURRENT_DIR" fetch origin 2>&1 || warn "Could not fetch ${DEFAULT_BRANCH} in ${CURRENT_DIR}"
else
warn "Could not switch to ${DEFAULT_BRANCH} in ${CURRENT_DIR}"
fi
fi

success "$CURRENT_DIR"
done
Loading