-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitcommitloop
More file actions
executable file
·101 lines (80 loc) · 1.9 KB
/
gitcommitloop
File metadata and controls
executable file
·101 lines (80 loc) · 1.9 KB
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
94
95
96
97
98
99
100
101
#!/bin/bash
#
# gitcommitloop
#
# uses the getyn script, which must be in the same directory.
usagestr=$(
cat <<EOF
usage: $(basename $0) [mode]
Optionally stage and commit all files identified by git as "modified",
"new file", "deleted", or "renamed".
modes
-b - [default] batch mode, all staged files will go into one commit
-s - single mode, each file will be committed separately
\0
EOF
)
prereqstr=$(
cat <<EOF
$(basename $0)
Requires the getyn script in the executable path.
\0
EOF
)
declare gitstat="$(git status)"
declare modfound=false
declare answer=1
declare batch=true
declare filelist=""
usage() {
echo -e "$usagestr"
exit
}
[ $# -ge 0 -a $# -le 1 ] || usage
which getyn
[ $? -ne 0 ] && { echo -e "$prereqstr"; exit 1; }
while getopts bsh OPTION; do
case "$OPTION" in
b ) batch=true
;;
s ) batch=false
;;
h ) usage
;;
* ) echo -e "\nunrecognized option"
echo -e "$usagestr"
exit 127
esac
done
# because we are going to invoke "read" with the call to getyn, we
# can't use "read .... <<< "$string", because the read buffer will
# have stuff from the string in it when we call getyn, which also
# uses read.
#
for str in $gitstat; do
mod=false; ren=false; del=false; new=false;
[ "$str" == "modified:" ] && mod=true
[ "$str" == "renamed:" ] && ren=true
[ "$str" == "deleted:" ] && del=true
[ "$str" == "file:" ] && new=true
$mod || $ren || $del || $new && { modfound=true; continue; }
if $modfound; then
clear
echo $str
modfound=false
[ -e "$str" ] && git diff $str || echo "Deleted file."
getyn "Do you want to stage this file?"
[ $? -ne 0 ] && continue
echo "git add $str"
git add $str
if $batch; then
filelist=$str" "$filelist
else
echo "git commit $str"
git commit $str
fi
echo -n "Press any key to continue..."
read -n1
fi
done
$batch && [ "$filelist" ] && { echo "git commit $filelist"; git commit $filelist; }