# HG changeset patch # User Tero Marttila # Date 1387489937 -7200 # Node ID bed4765fc56f5a807b62aecb60cf3524e94f3428 # Parent a756f317d083b5adbd954aff999ad5ef19faa21a fix hg commit message argument passing diff -r a756f317d083 -r bed4765fc56f lib/update.hg --- a/lib/update.hg Thu Dec 19 23:22:12 2013 +0200 +++ b/lib/update.hg Thu Dec 19 23:52:17 2013 +0200 @@ -28,20 +28,6 @@ echo "$hg_unix" } -## Output possible -u flag for commit. -function hg_user { - if [ ${SUDO_USER:-} ]; then - echo '-u' "$SUDO_USER" - - elif [ $HOME ] && [ -e $HOME/.hgrc ]; then - debug "using .hgrc user" - echo '' - - else - echo '-u' "$USER" - fi -} - ## Show changes in repo # hg_diff [path ...] function hg_diff { @@ -51,17 +37,39 @@ ## Commit changes in repo, with given message: # -# hg_commit $msg +# hg_commit .../etc $msg # # Automatically determines possible -u to use when running with sudo. function hg_commit { - local repo=$1 - local msg=$2 - local user_opt=$(hg_user) + local repo="$1" + local msg="$2" + local user_opt= local msg_opt= - [ $msg ] && msg_opt=('-m' "$msg") + if [ ${SUDO_USER:-} ]; then + user_opt=('-u' "$SUDO_USER") + + elif [ $HOME ] && [ -e $HOME/.hgrc ]; then + debug "using .hgrc user" + user_opt=( ) + + else + user_opt=('-u' "$USER") + fi - debug "$user_opt: $msg" - hg $repo commit ${user_opt[@]} ${msg_opt[@]} + if [ "$msg" ]; then + msg_opt=('-m' "$msg") + fi + + # XXX: there's something about bash arrays that I don't like... empty arrays behave badly + # mercurial does not like it if you pass it '' as an argument + if [ -n "${user_opt:-}" -a -n "${msg_opt:-}" ]; then + hg $repo commit "${user_opt[@]}" "${msg_opt[@]}" + elif [ -n "${user_opt:-}" ]; then + hg $repo commit "${user_opt[@]}" + elif [ -n "${msg_opt:-}" ]; then + hg $repo commit "${msg_opt[@]}" + else + hg $repo commit + fi } diff -r a756f317d083 -r bed4765fc56f lib/update.operations --- a/lib/update.operations Thu Dec 19 23:22:12 2013 +0200 +++ b/lib/update.operations Thu Dec 19 23:52:17 2013 +0200 @@ -334,24 +334,13 @@ } ### Commit -## Perform `hg commit` -function do_commit { - local repo=$1 - local msg=$1 - - [ $LOG_DIFF ] && indent " " hg_diff $repo - - hg_commit $repo "$msg" -} - - ## Commit changes to version control: # -# commit_data +# update_commit .../etc "commit message" # # Invokes `hg commit`, first showing the diff. function update_commit { - local repo=$1 + local repo="$1" local commit_msg="$COMMIT_MSG" local msg="Commit changes" @@ -360,19 +349,23 @@ if [ $COMMIT_FORCE ]; then log_force "$msg: $commit_msg" - do_commit "$commit_msg" + [ $LOG_DIFF ] && indent " " hg_diff $repo - elif ! hg_modified $repo; then + hg_commit "$repo" "$commit_msg" + + elif ! hg_modified "$repo"; then log_warn "$msg: no changes" elif [ $COMMIT_SKIP ]; then log_noop "$msg: skipped" # still show diff, though - [ $LOG_DIFF ] && indent " " hg_diff $repo + [ $LOG_DIFF ] && indent " " hg_diff "$repo" else log_update "$msg: $commit_msg" - do_commit $repo "$commit_msg" + [ $LOG_DIFF ] && indent " " hg_diff $repo + + hg_commit "$repo" "$commit_msg" fi }