add git cb

This commit is contained in:
Sebastian Bugge 2025-07-08 16:41:04 +02:00
parent 083385bd08
commit e97fef8036
2 changed files with 32 additions and 0 deletions

31
.local/bin/git-tmp-switch.sh Executable file
View file

@ -0,0 +1,31 @@
#!/bin/bash
set -euo pipefail
if [ "$#" -lt 1 ]; then
echo "Usage: git cb <target-branch>"
exit 1
fi
TARGET_BRANCH="$1"
if [ "$TARGET_BRANCH" != "-" ]; then
if ! git rev-parse --verify --quiet "$TARGET_BRANCH" >/dev/null; then
echo "Error: branch '$TARGET_BRANCH' does not exist." >&2
exit 1
fi
fi
git add -A
if ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
git commit -m "tmp"
fi
git checkout "$TARGET_BRANCH"
LATEST_AUTHOR=$(git log -1 --pretty=format:'%an')
LATEST_MESSAGE=$(git log -1 --pretty=format:'%s')
CURRENT_USER=$(git config user.name)
if [ "$LATEST_AUTHOR" = "$CURRENT_USER" ] && [ "$LATEST_MESSAGE" = "tmp" ]; then
echo "Resetting last 'tmp' commit by $CURRENT_USER..."
git reset --mixed HEAD~1
fi