added git_review_push.sh

pull/16/head
Hari Sekhon 1 week ago
parent 827ce6b866
commit 62cc5937a1

@ -0,0 +1,78 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2019-08-05 15:49:27 +0100
# (migrated out of .bash.d/git.sh and gitconfig for use in IntelliJ)
#
# https///github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090,SC1091
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Shows a git diff of what would be pushed and if you hit enter then pushes to origin remote
See also git_remotes_set_multi_origin.sh if you want to be able to push to multiple origin remotes for resilience
by using different platforms eg. GitHub, GitLab, Azure DevOps and Bitbucket
Lazy but awesome for lots of daily quick intermediate diff-review-pushes workflow
Migrated from .gitconfig alias and vimrc hotkey
Ported to external script be callable from IntelliJ as an External Tool because it's less keystrokes
and no mouse movement compared to IntelliJ's own hot key git commit tooling
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args=""
help_usage "$@"
num_args 0 "$@"
timestamp "Pulling to ensure we have the latest remote contents"
echo
git pull
echo
timestamp "Diffing HEAD vs FETCH_HEAD"
echo
commits="$(git log FETCH_HEAD..HEAD)"
diff="$(git diff FETCH_HEAD..HEAD | tee /dev/stderr)"
echo
if is_blank "$commits"; then
timestamp "No changes to push"
exit 0
fi
if is_blank "$diff"; then
timestamp "No changes to push, but commit difference (empty commits?)"
echo
fi
read -r -p "Push to origin remote? (Y/n) " answer
echo
if check_yes "$answer"; then
git push
else
timestamp "Aborting Push"
exit 0
fi
timestamp "Git Diff Review Push completed"
Loading…
Cancel
Save