From cd6c36ea307d6fb109e858d0b59913934b33474c Mon Sep 17 00:00:00 2001 From: William Hilton Date: Sun, 23 Aug 2020 14:48:02 -0400 Subject: [PATCH] reuse prev message if `g commit` fails. also --follow-tags --- bin/g | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/bin/g b/bin/g index e1b3a09..dc6f9b1 100755 --- a/bin/g +++ b/bin/g @@ -21,6 +21,14 @@ confirm () { esac } +confirmYes () { + read -r -n 1 -p "${1:-Are you sure? [Y/n]} " response + case $response in + [nN]) false ;; + *) true ;; + esac +} + case "$1" in '?' | status) # TODO: Display help if not inside a repo @@ -154,11 +162,23 @@ if [ -z "$2" ]; then parent_commit="$(git log --abbrev-commit -1 --pretty=format:'%C(bold blue)%s%Creset %Cgreen(%cr)%Creset' 2>/dev/null)" && echo "Parent commit: $parent_commit" # Interactive if [[ "$OSTYPE" == darwin* ]]; then - read -e -p 'Message: ' msg + if [[ -n "$current" ]]; then + if confirmYes "Message: $current [Y/n]"; then + msg="$current" + else + echo "" + read -e -p 'Message: ' msg + fi + else + read -e -p 'Message: ' msg + fi else read -e -p 'Message: ' -i "$current" msg fi + echo "$msg" > $msg_file + set -e git commit -m "$msg" + rm $msg_file else # Non-interactive msg="${@:2}" @@ -379,9 +399,22 @@ git diff --cached --ignore-all-space --ignore-blank-lines HEAD ^ | push) echo 'Pushing' +tags="$(git tag --points-at HEAD | tr '\n' ' ')" +follow_tags='' +if [ ! -z "$tags" ]; then + if confirm "Would you like to push these tags (${tags}) to the remote as well?"; then + local_branch=$(git rev-parse --abbrev-ref HEAD) + remote=$(git config --get branch.$local_branch.remote) + echo '' + follow_tags='--follow-tags' + else + echo '' + echo 'OK, just thought I'"'"'d ask.' + fi +fi # Check to see if upstream is set. if git rev-parse --abbrev-ref @{upstream} >/dev/null ; then - git push + git push ${follow_tags} else # Get local branch name local_branch=$(git rev-parse --abbrev-ref HEAD) @@ -401,18 +434,8 @@ else if [ "$remote_branch" = "" ]; then remote_branch="$local_branch" fi - echo "I will run git push --set-upstream ${remote} ${remote_branch}" - git push --set-upstream ${remote} ${remote_branch} -fi -tags="$(git tag --points-at HEAD | tr '\n' ' ')" -if [ ! -z "$tags" ] && confirm "Would you like to push these tags (${tags}) to the remote as well?"; then - local_branch=$(git rev-parse --abbrev-ref HEAD) - remote=$(git config --get branch.$local_branch.remote) - echo '' - git push ${remote} ${tags} -else - echo '' - echo 'OK, just thought I'"'"'d ask.' + echo "I will run git push --set-upstream ${remote} ${remote_branch} ${follow_tags}" + git push --set-upstream ${remote} ${remote_branch} ${follow_tags} fi ;;