ソースを参照

Allow push only per remote branch name

*Remote* branch name must be listed along with 'PUSH' keyword.

This requires predictable name of the remote, but as this whole slurping
thing is only meant for very dirty, very local scenarios, that should
not be problem.  (Other, more open scenarios are still possible, just
harder, as they probably should be.)
Alois Mahdal 8 年 前
コミット
7e37b46568
共有1 個のファイルを変更した20 個の追加2 個の削除を含む
  1. 20
    2
      dotfiles/gittum/bin/slurp

+ 20
- 2
dotfiles/gittum/bin/slurp ファイルの表示

@@ -26,9 +26,27 @@ allowed_slurp() {
26 26
 
27 27
 allowed_push() {
28 28
     #
29
-    # Is push allowed in this repo?
29
+    # Is push allowed for the remote branch??
30 30
     #
31
-    grep -qxF PUSH "$ok_file" 2>/dev/null
31
+    # If this branch is tracking a remote branch, and the remote
32
+    # branch name is listed in .git-slurp-ok after PUSH, we are
33
+    # allowed to push
34
+    #
35
+    # The remote tracking branch is parsed; example output is here:
36
+    #
37
+    #     $ git branch -vv
38
+    #       main   aaf02f0 [main/master: ahead 25] Some other commit
39
+    #     * master add0a03 [jdsumsion/master] Some commit
40
+    #
41
+    local tbranch=$(
42
+        git branch -vv \
43
+          | grep '^\*' \
44
+          | cut -d \] -f1 \
45
+          | cut -d \[ -f2 \
46
+          | cut -d :  -f1
47
+    )
48
+    test -n "$tbranch" || return 0
49
+    grep -qxF "PUSH $tbranch" "$ok_file" 2>/dev/null
32 50
 }
33 51
 
34 52
 git_relative() {