diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2018-05-13 22:22:15 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2018-05-13 22:22:28 +0300 |
commit | 358b3a68c11c6f54332674abf62a1c7fcb61d917 (patch) | |
tree | 52da8919c30d19bf6c8fe2792bdc6568fa660fe7 /%HOME% | |
parent | add Apport settings (diff) | |
download | linux-home-358b3a68c11c6f54332674abf62a1c7fcb61d917.tar.gz linux-home-358b3a68c11c6f54332674abf62a1c7fcb61d917.zip |
.gitconfig: even smarter alias.fixup
Diffstat (limited to '')
-rw-r--r-- | %HOME%/.gitconfig | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/%HOME%/.gitconfig b/%HOME%/.gitconfig index 8e60aa8..6ad8097 100644 --- a/%HOME%/.gitconfig +++ b/%HOME%/.gitconfig @@ -31,32 +31,57 @@ # 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 = "! \ -f() { \ - if ! git rev-parse --is-inside-work-tree >/dev/null ; then \ +__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 ; \ \ - add=-a ; \ - git diff --cached --quiet --exit-code || add= ; \ + 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 ; \ \ - if [ -z \"${add}\" ] ; then \ - echo \"There're unstaged changes, can't rebase.\" >&2 ; \ + 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 ; \ + echo 'Sure you want to fixup a merge commit?' >&2 ; \ return 1 ; \ fi ; \ \ - git commit $add --fixup=HEAD && GIT_EDITOR=true git rebase -i --autosquash \"$dest_ref\" ; \ + 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 ; \ } ; \ -f ; \ +__git_fixup ; \ " [fetch] prune = true |