You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.1 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
simpledelay.sh 2 # short delay to aid reading last message in case terminal closes on exit
exit "$code"
}
parse_params() {
while :; do
case "${1-}" in
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
return 0
}
parse_params "$@"
this_submod=${args[0]}
this_subtmp="${args[0]}_tmp"
# https://stackoverflow.com/a/16162228
msg "moving $this_submod to $this_subtmp"
mv $this_submod $this_subtmp
msg "git submodule deinit"
git submodule deinit $this_submod
msg "git rm $this_submod"
git rm $this_submod
msg "moving back $this_submod"
mv $this_subtmp $this_submod
msg "remove the existing .git file"
rm $this_submod/.git
msg "move the .git folder from modules into $this_submod"
mv .git/modules/$this_submod $this_submod/.git
msg "remove the worktree line from .git/config"
sed -i '/worktree/d' $this_submod/.git/config
msg "add $this_submod to .gitignore"
echo "$this_submod" >> .gitignore