-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitvb-unpick
executable file
·76 lines (56 loc) · 1.89 KB
/
gitvb-unpick
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -e
GITVB_HOME="./.git/.gitvb-v0"
MAIN_BRANCH="${MAIN_BRANCH:-main}"
if [ "$1" == "" ]; then
echo "usage: gitvb-unpick <branch>"
exit 1
fi
pickBranch="$1"
if [ ! -z "$(git diff --staged)" ]; then
echo "there are staged changes. exiting."
exit 1
fi
if [ "$(git branch --show-current)" != "$MAIN_BRANCH" ]; then
echo "you are not on the main branch: $MAIN_BRANCH"
exit 1
fi
# this is safe to always check because other gitvb programs stash before calling this
gitvb-is-unpickable "$pickBranch"
vbFilePath="$GITVB_HOME/$pickBranch.gitvb"
if [ ! -f "$vbFilePath" ]; then
echo "not picked $pickBranch"
exit 2
fi
gitvb-wip unpick
# vbFileContents="$(cat "$vbFilePath")"
# Extract foo value (single line)
base=$(awk -F'=' '/^base=/ {print $2}' $vbFilePath)
# Extract bar value (from bar= to the end of the file)
# applied=$(awk '/^applied=/{flag=1; sub(/^applied=/,""); print; next} flag' "$vbFilePath")
applied="$(git log --pretty=format:"%H %s" | fgrep "[gitvb:$pickBranch]" | awk '{print $1}')"
# git config core.abbrev 40 && EDITOR=nano git rebase -i b3eb88d3bc37ce79ed8f1f0cec440d404016da18 && git config --unset core.abbrev
echo "base:"
echo "$base"
echo "applied:"
echo "$applied"
if [ ! -z "$applied" ]; then
# commands=$(echo "$applied" | sed "s/^/drop /" | sed "s/'/'\\\\''/g" | awk '{printf "'\''%s'\'' ", $0}' | tr '\n' ' ')
commands=$(echo "$applied"| sed "s/^/drop /" | sed 's/.*/"&"/' | tr '\n' ' ')
echo "the commands: $commands"
echo "firing interactive rebase"
git config core.abbrev 40
LASTEDITOR="$EDITOR"
EDITOR="$(dirname $0)/gitvb-editor-interactive-rebase $commands"
git rebase -i "$base"
EDITOR="$LASTEDITOR"
# todo fire this on fail too
git config --unset core.abbrev
else
echo "none applied to undo"
fi
rm -v "$vbFilePath"
gitvb-wip-undo unpick
echo
echo "succesfully unpicked $pickBranch"
echo