瀏覽代碼

Add git_bool() for checking boolean git states

Alois Mahdal 8 年之前
父節點
當前提交
cbe1a156cc
共有 1 個檔案被更改,包括 23 行新增0 行删除
  1. 23
    0
      src/include/facts.sh

+ 23
- 0
src/include/facts.sh 查看文件

@@ -2,6 +2,29 @@
2 2
 
3 3
 . "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
4 4
 
5
+git_bool() {
6
+    #
7
+    # Get git bool (ie. exit status counts) $1
8
+    #
9
+    local bool_name="$1"
10
+    git_present || warn "can't give bool outside git repo: $bool_name"
11
+    case "$bool_name" in
12
+        dirty_files)
13
+            git diff-files | grep -qm 1 .
14
+            ;;
15
+        dirty_index)
16
+            git diff-index HEAD | grep -qm 1 .
17
+            ;;
18
+        dirty)
19
+            git_bool dirty_files || git_bool dirty_index
20
+            ;;
21
+        *)
22
+            warn "unknown git bool asked: $bool_name"
23
+            return 2
24
+            ;;
25
+    esac
26
+}
27
+
5 28
 git_fact() {
6 29
     #
7 30
     # Get git fact $1