|
@@ -4,23 +4,22 @@
|
4
|
4
|
# Slurp - add everything, slurp into a WIP commit and push
|
5
|
5
|
#
|
6
|
6
|
|
7
|
|
-die() {
|
|
7
|
+warn() {
|
8
|
8
|
echo "$@" >&2
|
|
9
|
+}
|
|
10
|
+
|
|
11
|
+die() {
|
|
12
|
+ warn "$@"
|
9
|
13
|
exit 2
|
10
|
14
|
}
|
11
|
15
|
|
12
|
|
-mkmsg() {
|
13
|
|
- #
|
14
|
|
- # Create the slurp message
|
15
|
|
- #
|
16
|
|
- local host=$(hostname)
|
17
|
|
- local date=$(date -Isec)
|
18
|
|
- echo "WIP slurp, $date at $host"
|
|
16
|
+usage() {
|
|
17
|
+ die "usage: git slurp [--force-slurp] [--force-push] [pathspec]..."
|
19
|
18
|
}
|
20
|
19
|
|
21
|
|
-allowed_anything() {
|
|
20
|
+allowed_slurp() {
|
22
|
21
|
#
|
23
|
|
- # Is anything allowed in this repo?
|
|
22
|
+ # Is slurp allowed in this repo?
|
24
|
23
|
#
|
25
|
24
|
test -f "$ok_file"
|
26
|
25
|
}
|
|
@@ -29,26 +28,72 @@ allowed_push() {
|
29
|
28
|
#
|
30
|
29
|
# Is push allowed in this repo?
|
31
|
30
|
#
|
32
|
|
- grep -qxF PUSH "$ok_file"
|
|
31
|
+ grep -qxF PUSH "$ok_file" 2>/dev/null
|
33
|
32
|
}
|
34
|
33
|
|
35
|
|
-main() {
|
36
|
|
- local git_root
|
37
|
|
- local ok_file
|
38
|
|
- local want_push=false
|
|
34
|
+git_relative() {
|
|
35
|
+ #
|
|
36
|
+ # Convert pathspec $1 to git-root-based pathspec
|
|
37
|
+ #
|
|
38
|
+ # Also try to clean up path a bit; i.e. remove double slashes
|
|
39
|
+ # or unnecessary trailing dot.
|
|
40
|
+ #
|
|
41
|
+ local path="$1"
|
|
42
|
+ test -n "$GIT_PREFIX" && path="$GIT_PREFIX/$path"
|
|
43
|
+ local full=$(readlink -m "$path")
|
|
44
|
+ printf %s "${full#$git_root/}"
|
|
45
|
+}
|
39
|
46
|
|
40
|
|
- git_root="$(git rev-parse --show-toplevel)" || die
|
41
|
|
- ok_file="$git_root/.git-slurp-ok"
|
|
47
|
+slurp1() {
|
|
48
|
+ #
|
|
49
|
+ # Slurp pathspec $1
|
|
50
|
+ #
|
|
51
|
+ local rel_pathspec # relative to git root
|
|
52
|
+ rel_pathspec=$(git_relative "$1")
|
|
53
|
+ git add "$rel_pathspec" || die
|
|
54
|
+ git commit -m "WIP slurp, $date: $rel_pathspec" || die
|
|
55
|
+}
|
42
|
56
|
|
43
|
|
- allowed_anything || die "you don't want this."
|
44
|
|
- allowed_push && want_push=true
|
|
57
|
+go_slurp() {
|
|
58
|
+ #
|
|
59
|
+ # Do the slurp for pathspecs $@
|
|
60
|
+ #
|
|
61
|
+ $force_slurp || allowed_slurp || die "you don't want this."
|
|
62
|
+ local date=$(date -Isec)
|
|
63
|
+ local pathspec
|
|
64
|
+ for pathspec in "$@";
|
|
65
|
+ do
|
|
66
|
+ slurp1 "$pathspec"
|
|
67
|
+ done
|
|
68
|
+}
|
45
|
69
|
|
46
|
|
- git add .
|
47
|
|
- git commit -m "$(mkmsg)"
|
48
|
|
- if $want_push;
|
|
70
|
+go_push() {
|
|
71
|
+ #
|
|
72
|
+ # Do the push (if allowed)
|
|
73
|
+ #
|
|
74
|
+ if $force_push || allowed_push;
|
49
|
75
|
then
|
50
|
76
|
git push
|
51
|
77
|
fi
|
52
|
78
|
}
|
53
|
79
|
|
54
|
|
-main
|
|
80
|
+main() {
|
|
81
|
+ local git_root
|
|
82
|
+ local ok_file
|
|
83
|
+ local force_slurp=false
|
|
84
|
+ local force_push=false
|
|
85
|
+ while true; do case $1 in
|
|
86
|
+ --force-slurp) force_slurp=true; shift ;;
|
|
87
|
+ --force-push) force_push=true; shift ;;
|
|
88
|
+ --) shift; break ;;
|
|
89
|
+ -*) usage ;;
|
|
90
|
+ *) break ;;
|
|
91
|
+ esac done
|
|
92
|
+ test -n "$1" || set -- .
|
|
93
|
+ git_root="$(git rev-parse --show-toplevel)" || die
|
|
94
|
+ ok_file="$git_root/.git-slurp-ok"
|
|
95
|
+ go_slurp "$@"
|
|
96
|
+ go_push
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+main "$@"
|