26 [ -n "$hg_unix" ] || fail "failed to read hg time" |
26 [ -n "$hg_unix" ] || fail "failed to read hg time" |
27 |
27 |
28 echo "$hg_unix" |
28 echo "$hg_unix" |
29 } |
29 } |
30 |
30 |
31 ## Output possible -u flag for commit. |
|
32 function hg_user { |
|
33 if [ ${SUDO_USER:-} ]; then |
|
34 echo '-u' "$SUDO_USER" |
|
35 |
|
36 elif [ $HOME ] && [ -e $HOME/.hgrc ]; then |
|
37 debug "using .hgrc user" |
|
38 echo '' |
|
39 |
|
40 else |
|
41 echo '-u' "$USER" |
|
42 fi |
|
43 } |
|
44 |
|
45 ## Show changes in repo |
31 ## Show changes in repo |
46 # hg_diff [path ...] |
32 # hg_diff [path ...] |
47 function hg_diff { |
33 function hg_diff { |
48 local repo=$1; shift |
34 local repo=$1; shift |
49 hg $repo diff "$@" |
35 hg $repo diff "$@" |
50 } |
36 } |
51 |
37 |
52 ## Commit changes in repo, with given message: |
38 ## Commit changes in repo, with given message: |
53 # |
39 # |
54 # hg_commit $msg |
40 # hg_commit .../etc $msg |
55 # |
41 # |
56 # Automatically determines possible -u to use when running with sudo. |
42 # Automatically determines possible -u to use when running with sudo. |
57 function hg_commit { |
43 function hg_commit { |
58 local repo=$1 |
44 local repo="$1" |
59 local msg=$2 |
45 local msg="$2" |
60 local user_opt=$(hg_user) |
46 local user_opt= |
61 local msg_opt= |
47 local msg_opt= |
62 |
48 |
63 [ $msg ] && msg_opt=('-m' "$msg") |
49 if [ ${SUDO_USER:-} ]; then |
|
50 user_opt=('-u' "$SUDO_USER") |
|
51 |
|
52 elif [ $HOME ] && [ -e $HOME/.hgrc ]; then |
|
53 debug "using .hgrc user" |
|
54 user_opt=( ) |
|
55 |
|
56 else |
|
57 user_opt=('-u' "$USER") |
|
58 fi |
64 |
59 |
65 debug "$user_opt: $msg" |
60 if [ "$msg" ]; then |
66 hg $repo commit ${user_opt[@]} ${msg_opt[@]} |
61 msg_opt=('-m' "$msg") |
|
62 fi |
|
63 |
|
64 # XXX: there's something about bash arrays that I don't like... empty arrays behave badly |
|
65 # mercurial does not like it if you pass it '' as an argument |
|
66 if [ -n "${user_opt:-}" -a -n "${msg_opt:-}" ]; then |
|
67 hg $repo commit "${user_opt[@]}" "${msg_opt[@]}" |
|
68 elif [ -n "${user_opt:-}" ]; then |
|
69 hg $repo commit "${user_opt[@]}" |
|
70 elif [ -n "${msg_opt:-}" ]; then |
|
71 hg $repo commit "${msg_opt[@]}" |
|
72 else |
|
73 hg $repo commit |
|
74 fi |
67 } |
75 } |