소스 검색

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 9 년 전
부모
커밋
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() {