Skip to content

Commit

Permalink
dev: add @git-submodule-rm task
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Oct 25, 2023
1 parent 56d8a6d commit 8216f03
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions Taskfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions bin/lib/git/core.bash
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions bin/lib/git/submodule.bash
Original file line number Diff line number Diff line change
@@ -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}"
}

0 comments on commit 8216f03

Please sign in to comment.