-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-co
executable file
·93 lines (75 loc) · 1.79 KB
/
git-co
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# The motto: Alias for `git checkout`
source $(dirname $0)/colors
bailout() {
echo -n "Branch: "; $CYAN; git cbr; $RESET
echo $ALTERNATIVES
exit
}
default_checkout () {
echo "Commencing the default checkout"
git checkout $*
bailout
}
parse_id() {
PARSEDID=$1
ID=`git rev-parse --verify -q $PARSEDID 2>/dev/null || echo ""`
}
try_checkout() {
TRYID=$1
parse_id $TRYID
if [ "$ID" == "" ]
then
# echo "Could not find $TRYID"
return 1
fi
echo "Checking out $*"
git checkout $TRYID
# echo $?
git dibst
bailout
}
if [ "$#" != "1" ]; then
default_checkout $*
fi
COMMIT=$1
echo $COMMIT | egrep -q ^[[:digit:]]\{1,4\}$
if [ "$?" == "1" ]; then
default_checkout $*
fi
try_checkout "$COMMIT"
try_checkout "feature/$COMMIT"
ALTERNATIVES=`git brr | grep -w $COMMIT | awk '{ print gensub("origin/", "", $1); }'| tr -d '\n'`
ALTERNATIVESCOUNT=`echo $ALTERNATIVES | wc -w`
if [ "$ALTERNATIVESCOUNT" == "0" ]; then
ALTERNATIVES=`git brr|egrep -e [^[:digit:]]$COMMIT$ -e [^[:digit:]]$COMMIT[^[:digit:]]`
ALTERNATIVESCOUNT=`echo $ALTERNATIVES | wc -w`
fi
if [ "$ALTERNATIVESCOUNT" == "0" ]; then
ALTERNATIVES=`git br|egrep -e [^[:digit:]]$COMMIT$ -e [^[:digit:]]$COMMIT[^[:digit:]]`
ALTERNATIVESCOUNT=`echo $ALTERNATIVES | wc -w`
fi
# echo $ALTERNATIVES
# echo $ALTERNATIVESCOUNT
# exit
if [ "$ALTERNATIVESCOUNT" == "0" ]; then
ALTERNATIVES=`git brr|egrep -e [^[:digit:]]$COMMIT$ -e [^[:digit:]]$COMMIT[^[:digit:]]`
bailout
fi
if [ "$ALTERNATIVESCOUNT" == "1" ]; then
try_checkout $ALTERNATIVES
default_checkout $ALTERNATIVES
fi
DIALOG=""
j=0
for i in $ALTERNATIVES
do
j=$((j+1))
DIALOG="$DIALOG $i $j off"
done
SELECTION=`dialog --radiolist "What to checkout?" 20 100 19 $DIALOG 3>&1 1>&2 2>&3 3>&-`
if [ -z "$SELECTION" ]; then
echo "No selection"
bailout
fi
default_checkout $SELECTION