31 lines
784 B
Bash
Executable file
31 lines
784 B
Bash
Executable file
#!/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
|