Bladeren bron

Rewrite git-slurp to have "some" style

 *  Die by dedicated function.

 *  Push only if allowed (a line containing single word PUSH found in
    .git-slurp-ok file)

 *  Allow working when deeper in git repo (but not if outside).

 *  Make permisson code readable (self-doc).

 *  Enclose in main() to allow for better hygiene.
Alois Mahdal 9 jaren geleden
bovenliggende
commit
561312b3c7
1 gewijzigde bestanden met toevoegingen van 33 en 5 verwijderingen
  1. 33
    5
      dotfiles/gittum/bin/slurp

+ 33
- 5
dotfiles/gittum/bin/slurp Bestand weergeven

4
 # Slurp - add everything, slurp into a WIP commit and push
4
 # Slurp - add everything, slurp into a WIP commit and push
5
 #
5
 #
6
 
6
 
7
-test -f .git-slurp-ok || {
8
-    echo "you don't want this." >&2
7
+die() {
8
+    echo "$@" >&2
9
     exit 2
9
     exit 2
10
 }
10
 }
11
 
11
 
18
     echo "WIP slurp, $date at $host"
18
     echo "WIP slurp, $date at $host"
19
 }
19
 }
20
 
20
 
21
-git add .
22
-git commit -m "$(mkmsg)"
23
-git push
21
+allowed_anything() {
22
+    #
23
+    # Is anything allowed in this repo?
24
+    #
25
+    test -f "$ok_file"
26
+}
27
+
28
+allowed_push() {
29
+    #
30
+    # Is push allowed in this repo?
31
+    #
32
+    grep -qxF PUSH "$ok_file"
33
+}
34
+
35
+main() {
36
+    local git_root
37
+    local ok_file
38
+    local want_push=false
39
+
40
+    git_root="$(git rev-parse --show-toplevel)" || die
41
+    ok_file="$git_root/.git-slurp-ok"
42
+
43
+    allowed_anything || die "you don't want this."
44
+    allowed_push     && want_push=true
45
+
46
+    git add .
47
+    git commit -m "$(mkmsg)"
48
+    $want_push && git push
49
+}
50
+
51
+main