diff --git a/Taskfile b/Taskfile index 3ef0f7f..05a568a 100755 --- a/Taskfile +++ b/Taskfile @@ -9,6 +9,7 @@ set -euo pipefail root=$(git rev-parse --show-toplevel) include=( + "${root}"/bin/lib/git/*.bash "${root}"/bin/lib/config/*.bash "${root}"/bin/lib/core/*.bash "${root}"/bin/lib/main.bash diff --git a/bin/lib/git/core.bash b/bin/lib/git/core.bash new file mode 100644 index 0000000..820eba3 --- /dev/null +++ b/bin/lib/git/core.bash @@ -0,0 +1,22 @@ +@root() { git rev-parse --show-toplevel; } + +@pull() { + local remote + for remote in $(git remote | grep -v origin); do + git fetch --prune --tags "${remote}" + done + git fetch --prune --tags --prune-tags origin + + local remote actual target shared + remote=${1:-'@{u}'} + actual=$(git rev-parse @) + target=$(git rev-parse "${remote}") + shared="$(git merge-base @ "${remote}")" + if [ "${actual}" != "${target}" ]; then + if ! git diff-index --quiet HEAD; then + git stash -m 'stash before pulling' + trap 'git stash pop' EXIT + fi + git pull --force --rebase + fi +} diff --git a/bin/lib/git/submodule.bash b/bin/lib/git/submodule.bash new file mode 100644 index 0000000..898b56d --- /dev/null +++ b/bin/lib/git/submodule.bash @@ -0,0 +1,12 @@ +# issue: https://github.com/kamilsk/dotfiles/issues/601 +@git-submodule-rm() { + local submodule="${1}" + + git submodule status "${submodule}" || return 1 + git --no-pager config -f .gitmodules --get-regexp "submodule.${submodule}" + + git submodule deinit -f "${submodule}" + rm -rf ".git/modules/${submodule}" + git rm -f "${submodule}" + git config -f .gitmodules --remove-section "submodule.${submodule}" +}