From 347a68546c0d7df97000bc2a80ebd1d5ceb39e40 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 24 Jan 2020 17:14:45 +0300 Subject: .gitconfig: no more external scripts --- %HOME%/.gitconfig | 10 +++++++ %HOME%/.local/bin/git-fixup | 58 ----------------------------------------- %HOME%/.local/bin/git-fixup-old | 58 +++++++++++++++++++++++++++++++++++++++++ %HOME%/.local/bin/git-pulll | 8 ------ %HOME%/.local/bin/git-pulll-old | 8 ++++++ 5 files changed, 76 insertions(+), 66 deletions(-) delete mode 100755 %HOME%/.local/bin/git-fixup create mode 100644 %HOME%/.local/bin/git-fixup-old delete mode 100755 %HOME%/.local/bin/git-pulll create mode 100644 %HOME%/.local/bin/git-pulll-old (limited to '%HOME%') diff --git a/%HOME%/.gitconfig b/%HOME%/.gitconfig index 07b1c3b..5369d34 100644 --- a/%HOME%/.gitconfig +++ b/%HOME%/.gitconfig @@ -15,11 +15,17 @@ # If no refspec is given, push to the branch with the same name. default = upstream +# Git submodules suck, but they suck less if you read +# https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407. + # Show submodule changes in a more verbose way. [diff] submodule = log [status] submoduleSummary = true +[alias] + # Pull and sync submodules. + pulll = !git pull && git submodule sync --recursive && git submodule update --init --recursive # Automatically remove obsolete things/publish new things. [fetch] @@ -62,6 +68,10 @@ unhide = update-index --no-skip-worktree hidden = !git ls-files -v | grep --basic-regexp \"^\\([[:lower:]]\\|S\\)\" + # Squash the staging area with the latest commit. + # Pass "-a" to skip using `git add`. + fixup = !GIT_EDITOR=true git commit --amend + [filter "lfs"] smudge = git-lfs smudge -- %f process = git-lfs filter-process diff --git a/%HOME%/.local/bin/git-fixup b/%HOME%/.local/bin/git-fixup deleted file mode 100755 index 3883f10..0000000 --- a/%HOME%/.local/bin/git-fixup +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2018 Egor Tensin -# This file is part of the "Linux/Cygwin environment" project. -# For details, see https://github.com/egor-tensin/linux-home. -# Distributed under the MIT License. - -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" diff --git a/%HOME%/.local/bin/git-fixup-old b/%HOME%/.local/bin/git-fixup-old new file mode 100644 index 0000000..3883f10 --- /dev/null +++ b/%HOME%/.local/bin/git-fixup-old @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# Copyright (c) 2018 Egor Tensin +# This file is part of the "Linux/Cygwin environment" project. +# For details, see https://github.com/egor-tensin/linux-home. +# Distributed under the MIT License. + +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" diff --git a/%HOME%/.local/bin/git-pulll b/%HOME%/.local/bin/git-pulll deleted file mode 100755 index 79299e5..0000000 --- a/%HOME%/.local/bin/git-pulll +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -# This is cool: -# https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407 - -git pull "$@" \ - && git submodule sync --recursive \ - && git submodule update --init --recursive diff --git a/%HOME%/.local/bin/git-pulll-old b/%HOME%/.local/bin/git-pulll-old new file mode 100644 index 0000000..79299e5 --- /dev/null +++ b/%HOME%/.local/bin/git-pulll-old @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# This is cool: +# https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407 + +git pull "$@" \ + && git submodule sync --recursive \ + && git submodule update --init --recursive -- cgit v1.2.3