add git cb
This commit is contained in:
parent
083385bd08
commit
e97fef8036
2 changed files with 32 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
||||||
autoSquash = true
|
autoSquash = true
|
||||||
[alias]
|
[alias]
|
||||||
publish = !git pull && git push
|
publish = !git pull && git push
|
||||||
|
cb = !git-tmp-switch.sh
|
||||||
[push]
|
[push]
|
||||||
default = current
|
default = current
|
||||||
autoSetupRemote = true
|
autoSetupRemote = true
|
||||||
|
|
31
.local/bin/git-tmp-switch.sh
Executable file
31
.local/bin/git-tmp-switch.sh
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue