Browse Source

Add git_bool() for checking boolean git states

Alois Mahdal 8 years ago
parent
commit
cbe1a156cc
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      src/include/facts.sh

+ 23
- 0
src/include/facts.sh View File

2
 
2
 
3
 . "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
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
 git_fact() {
28
 git_fact() {
6
     #
29
     #
7
     # Get git fact $1
30
     # Get git fact $1