From 542e603f7c3d17dd797a8c194ecd2ad4933eefef Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 14 May 2018 13:40:05 +0300 Subject: .gitconfig: move alias.fixup to a separate script --- %HOME%/.bashrc | 3 +++ %HOME%/.gitconfig | 56 --------------------------------------------- %HOME%/.local/bin/git-fixup | 53 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 56 deletions(-) create mode 100755 %HOME%/.local/bin/git-fixup (limited to '%HOME%') diff --git a/%HOME%/.bashrc b/%HOME%/.bashrc index 0ce7b81..93dc3e2 100644 --- a/%HOME%/.bashrc +++ b/%HOME%/.bashrc @@ -87,3 +87,6 @@ fi os_is_cygwin \ || command -v stty > /dev/null 2>&1 \ && stty -ixon + +command -v path_export > /dev/null 2>&1 \ + && path_export "$HOME/.local/bin" diff --git a/%HOME%/.gitconfig b/%HOME%/.gitconfig index 6ad8097..720cf1d 100644 --- a/%HOME%/.gitconfig +++ b/%HOME%/.gitconfig @@ -27,62 +27,6 @@ hide = update-index --skip-worktree unhide = update-index --no-skip-worktree hidden = !git ls-files -v | grep --basic-regexp \"^\\([[:lower:]]\\|S\\)\" - - # I heard git might use sh for aliases, so I tried to keep that in - # mind. Didn't want to bother with an external script. - fixup = "! \ -__git_fixup() { \ - if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1 ; then \ - echo 'Not inside a Git repository.' >&2 ; \ - return 1 ; \ - fi ; \ -\ - if ! git rev-parse HEAD >/dev/null 2>&1 ; then \ - echo \"Where's your HEAD?\" >&2 ; \ - return 1 ; \ - fi ; \ -\ - has_staged_changes= ; \ - git diff --cached --ignore-submodules --quiet || has_staged_changes=1 ; \ -\ - has_unstaged_changes= ; \ - git diff --ignore-submodules --quiet || has_unstaged_changes=1 ; \ -\ - if [ -z \"${has_staged_changes}\" ] && [ -z \"${has_unstaged_changes}\" ]; then \ - echo 'No staged or unstaged changes, seemingly?' >&2 ; \ - return 1 ; \ - fi ; \ -\ - add=-a ; \ - [ -n \"$has_staged_changes\" ] && add= ; \ -\ - numof_parents=`git rev-list --parents -n 1 HEAD | wc --words` ; \ - if [ \"$numof_parents\" -eq 1 ] ; then \ - dest_ref=--root ; \ - elif [ \"$numof_parents\" -eq 2 ] ; then \ - dest_ref=HEAD^^ ; \ - else \ - echo 'Sure you want to fixup a merge commit?' >&2 ; \ - return 1 ; \ - fi ; \ -\ - git commit $add --fixup=HEAD || return $? ; \ -\ - stash= ; \ - [ -n \"$has_staged_changes\" ] && [ -n \"$has_unstaged_changes\" ] && stash=1 ; \ -\ - if [ -n \"$stash\" ]; then \ - git stash push --quiet || return $? ; \ - fi ; \ -\ - GIT_EDITOR=true git rebase -i --autosquash \"$dest_ref\" || return $? ; \ -\ - if [ -n \"$stash\" ]; then \ - git stash pop --quiet || return $? ; \ - fi ; \ -} ; \ -__git_fixup ; \ -" [fetch] prune = true [log] diff --git a/%HOME%/.local/bin/git-fixup b/%HOME%/.local/bin/git-fixup new file mode 100755 index 0000000..b721ffe --- /dev/null +++ b/%HOME%/.local/bin/git-fixup @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then + echo 'Not inside a Git repository.' >&2 + exit 1 +fi + +if ! git rev-parse HEAD > /dev/null 2>&1 ; then + echo "Where's your HEAD?" >&2 + exit 1 +fi + +has_staged_changes= +git diff --cached --ignore-submodules --quiet || has_staged_changes=1 + +has_unstaged_changes= +git diff --ignore-submodules --quiet || has_unstaged_changes=1 + +if [ -z "$has_staged_changes" ] && [ -z "$has_unstaged_changes" ]; then + echo 'No staged or unstaged changes, seemingly?' >&2 + exit 1 +fi + +add=-a +[ -n "$has_staged_changes" ] && add= + +numof_parents="$( git rev-list --parents -n 1 HEAD | wc --words )" +if [ "$numof_parents" -eq 1 ]; then + dest_ref=--root +elif [ "$numof_parents" -eq 2 ]; then + dest_ref='HEAD^^' +else + echo 'Sure you want to fixup a merge commit?' >&2 + exit 1 +fi + +git commit $add --fixup=HEAD + +stash= +[ -n "$has_staged_changes" ] && [ -n "$has_unstaged_changes" ] && stash=1 + +unstash() { + git stash pop --quiet +} + +if [ -n "$stash" ]; then + git stash push --quiet + trap unstash EXIT +fi + +GIT_EDITOR=true git rebase -i --autosquash "$dest_ref" -- cgit v1.2.3