author | Tero Marttila <tero.marttila@aalto.fi> |
Fri, 27 Feb 2015 18:07:32 +0200 | |
branch | 0.8 |
changeset 654 | 8069b08e90ac |
parent 632 | 711be783d0a1 |
permissions | -rw-r--r-- |
627 | 1 |
# VCS abstraction layer |
2 |
||
3 |
. $LIB/pvl/commit/git.sh |
|
4 |
. $LIB/pvl/commit/hg.sh |
|
5 |
||
629 | 6 |
commit_GETOPTS='cCm:M' |
627 | 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 |
|
629 | 18 |
-M interactive commit message |
627 | 19 |
END |
20 |
} |
|
21 |
||
22 |
function commit_opt { |
|
23 |
local opt=$1 |
|
24 |
local optarg="$2" |
|
25 |
||
26 |
case $opt in |
|
27 |
c) COMMIT=1 ;; |
|
28 |
C) COMMIT=0 ;; |
|
29 |
||
30 |
m) COMMIT_MSG="$optarg" ;; |
|
629 | 31 |
M) COMMIT_MSG= ;; |
627 | 32 |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
33 |
n) COMMIT=0 ;; |
627 | 34 |
p) COMMIT_DIFF=1 ;; |
35 |
*) return 1 |
|
36 |
esac |
|
37 |
} |
|
38 |
||
39 |
function commit_probe { |
|
40 |
local repo="$1" |
|
41 |
||
42 |
for commit in git hg; do |
|
43 |
if ${commit}_probe "$repo"; then |
|
44 |
echo $commit |
|
45 |
return 0 |
|
46 |
fi |
|
47 |
done |
|
48 |
||
49 |
return 1 |
|
50 |
} |
|
51 |
||
52 |
## Commit changes to version control: |
|
53 |
# |
|
54 |
# update_commit .../etc "commit message" |
|
55 |
# |
|
56 |
# Invokes `hg commit`, first showing the diff. |
|
57 |
function commit { |
|
58 |
local repo="$1" |
|
59 |
local commit_msg="$COMMIT_MSG" |
|
60 |
||
61 |
# detect |
|
62 |
local commit="$(commit_probe "$repo")" |
|
63 |
||
64 |
if [ -z "$commit" ]; then |
|
65 |
log_warn "$repo: Unable to detect VCS repo" |
|
66 |
return 1 |
|
67 |
fi |
|
68 |
||
69 |
# operate? |
|
70 |
if [ "$COMMIT" = 1 ]; then |
|
632 | 71 |
log_force "$repo: force commit" |
627 | 72 |
|
629 | 73 |
[ "$COMMIT_DIFF" ] && cmd_indent " " ${commit}_diff "$repo" || true |
627 | 74 |
|
75 |
${commit}_commit "$repo" "$commit_msg" |
|
76 |
||
77 |
elif ! ${commit}_modified "$repo"; then |
|
632 | 78 |
log_skip "$repo: no changes to commit" |
627 | 79 |
|
80 |
elif [ "$COMMIT" = 0 ]; then |
|
632 | 81 |
log_noop "$repo: skip commit" |
627 | 82 |
|
83 |
# still show diff, though |
|
629 | 84 |
[ "$COMMIT_DIFF" ] && cmd_indent " " ${commit}_diff "$repo" || true |
627 | 85 |
else |
632 | 86 |
log_apply "$repo: commit: $commit_msg" |
627 | 87 |
|
629 | 88 |
[ "$COMMIT_DIFF" ] && cmd_indent " " ${commit}_diff "$repo" || true |
627 | 89 |
|
90 |
${commit}_commit "$repo" "$commit_msg" |
|
91 |
fi |
|
92 |
} |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
93 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
94 |
function _commit { |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
95 |
local repo="$1" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
96 |
local cmd="$2" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
97 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
98 |
# detect |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
99 |
local commit="$(commit_probe "$repo")" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
100 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
101 |
if [ -z "$commit" ]; then |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
102 |
log_warn "$repo: Unable to detect VCS repo" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
103 |
return 1 |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
104 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
105 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
106 |
${commit}_${cmd} $repo "${@:3}" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
107 |
} |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
108 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
109 |
function commit_modified { |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
110 |
local repo="$1" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
111 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
112 |
_commit $repo modified |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
113 |
} |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
114 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
115 |
function commit_time { |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
116 |
local repo="$1" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
117 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
118 |
_commit $repo time |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
119 |
} |