From e9feecc440322301ceb651f225ec0d07ae09fdf3 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 25 May 2020 17:36:27 +0200 Subject: [PATCH] [git] Fix git stash alias,set default pull options Fixed git stash alias (gsta) not correctly detecting zsh shell for git version guessing. Set default options to automatically rebase on pull, automatically prune on fetch, and automatically stash and squash on rebasing. Also made git diff highlight moved code. --- git/.config/git/config | 22 +++++++++++++++++----- git/.config/sh/alias.d/git.sh | 9 +++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/git/.config/git/config b/git/.config/git/config index 13fddef..709e44e 100644 --- a/git/.config/git/config +++ b/git/.config/git/config @@ -10,6 +10,23 @@ [alias] ignore = "!gitignore -f" pushmerge = "push -o merge_request.merge_when_pipeline_succeeds" # see https://docs.gitlab.com/ce/user/project/push_options.html#merge-when-pipeline-succeeds-alias +[commit] + # sign commits as me + gpgsign = true + # Always show diff when preparing commit message + verbose = true +[fetch] + # remove references to non-existent remote branches + prune = true +[pull] + rebase = true # always rebase on pulling, obviates merge commits +[diff] + colorMoved = zebra # also color stuff that has simply been moved, in a classy zebra-color +[rebase] + autostash = true + autoSquash = true +# Make use of git urls for git{lab,hub}, but only do so for pushing +# since pulling will create troubles with some applications [url "git@github.com:"] pushInsteadOf = "https://github.com/" pushInsteadOf = "http://github.com/" @@ -17,8 +34,3 @@ [url "git@gitlab.com:"] pushInsteadOf = "https://gitlab.com" pushInsteadOf = "http://gitlab.com" -[commit] - # sign commits as me - gpgsign = true - # Show diff when preparing commit message - verbose = true diff --git a/git/.config/sh/alias.d/git.sh b/git/.config/sh/alias.d/git.sh index 6122588..df18680 100644 --- a/git/.config/sh/alias.d/git.sh +++ b/git/.config/sh/alias.d/git.sh @@ -47,14 +47,19 @@ if exist git; then alias gst='git status' - if [ "$0" = "/bin/zsh" ]; then + # if git is at least version 2.13, we can use git stash push + # in shells other than zsh, simply fall back to save + case "$(ps -cp "$$" -o command="")" in + *zsh*) autoload -Uz is-at-least if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then alias gsta='git stash push' else alias gsta='git stash save' fi - fi + ;; + *) alias gsta='git stash save' ;; + esac alias gstp='git stash pop' alias gstl='git stash list' fi