-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-stack
More file actions
executable file
·34 lines (28 loc) · 852 Bytes
/
git-stack
File metadata and controls
executable file
·34 lines (28 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# git-stack: create a new branch stacked on the current one
set -e
# Work around kcov --bash-handle-sh-invocation (v42) duplicating argv[0] into $1.
# See kcov src/engines/bash-execve-redirector.c — its argv-rebuild loop starts
# at i=0, so the script path arrives twice. Shift it off if we see it.
if [ $# -gt 0 ] && { [ "$1" = "$0" ] || [ "$1" = "${0##*/}" ]; }; then
shift
fi
if [ -z "$1" ]; then
echo "Usage: git stack <branch-name>"
exit 1
fi
CURRENT=$(git branch --show-current)
if [ -z "$CURRENT" ]; then
echo "Error: not on a branch."
exit 1
fi
NEW="$1"
if git show-ref --verify --quiet "refs/heads/$NEW"; then
echo "Error: branch '$NEW' already exists."
exit 1
fi
git checkout -b "$NEW"
git config "branch.$NEW.stack-parent" "$CURRENT"
echo "Stacked '$NEW' on '$CURRENT'"
echo ""
git stack-tree