|
1 # VCS abstraction layer |
|
2 |
|
3 . $LIB/pvl/commit/git.sh |
|
4 . $LIB/pvl/commit/hg.sh |
|
5 |
|
6 commit_GETOPTS='cCm:' |
|
7 |
|
8 COMMIT= |
|
9 COMMIT_DIFF= |
|
10 COMMIT_MSG=' ' |
|
11 |
|
12 function commit_help { |
|
13 cat <<END |
|
14 Commit: |
|
15 -C do not commit changes |
|
16 -c commit changes |
|
17 -m MSG commit message |
|
18 END |
|
19 } |
|
20 |
|
21 function commit_opt { |
|
22 local opt=$1 |
|
23 local optarg="$2" |
|
24 |
|
25 case $opt in |
|
26 c) COMMIT=1 ;; |
|
27 C) COMMIT=0 ;; |
|
28 |
|
29 m) COMMIT_MSG="$optarg" ;; |
|
30 |
|
31 n) COMMIT= ;; |
|
32 p) COMMIT_DIFF=1 ;; |
|
33 *) return 1 |
|
34 esac |
|
35 } |
|
36 |
|
37 function commit_probe { |
|
38 local repo="$1" |
|
39 |
|
40 for commit in git hg; do |
|
41 if ${commit}_probe "$repo"; then |
|
42 echo $commit |
|
43 return 0 |
|
44 fi |
|
45 done |
|
46 |
|
47 return 1 |
|
48 } |
|
49 |
|
50 ## Commit changes to version control: |
|
51 # |
|
52 # update_commit .../etc "commit message" |
|
53 # |
|
54 # Invokes `hg commit`, first showing the diff. |
|
55 function commit { |
|
56 local repo="$1" |
|
57 local commit_msg="$COMMIT_MSG" |
|
58 |
|
59 # detect |
|
60 local commit="$(commit_probe "$repo")" |
|
61 |
|
62 if [ -z "$commit" ]; then |
|
63 log_warn "$repo: Unable to detect VCS repo" |
|
64 return 1 |
|
65 fi |
|
66 |
|
67 # operate? |
|
68 if [ "$COMMIT" = 1 ]; then |
|
69 log_force "$repo: force commit" |
|
70 |
|
71 [ $COMMIT_DIFF ] && indent " " ${commit}_diff "$repo" |
|
72 |
|
73 ${commit}_commit "$repo" "$commit_msg" |
|
74 |
|
75 elif ! ${commit}_modified "$repo"; then |
|
76 log_warn "$repo: no changes to commit" |
|
77 |
|
78 elif [ "$COMMIT" = 0 ]; then |
|
79 log_noop "$repo: skip commit" |
|
80 |
|
81 # still show diff, though |
|
82 [ $COMMIT_DIFF ] && indent " " ${commit}_diff "$repo" |
|
83 else |
|
84 log_apply "$repo: commit: $commit_msg" |
|
85 |
|
86 [ $COMMIT_DIFF ] && indent " " ${commit}_diff "$repo" |
|
87 |
|
88 ${commit}_commit "$repo" "$commit_msg" |
|
89 fi |
|
90 } |