From 2aded2bfc5e2b60b54d46596cda64ff05d19c2e1 Mon Sep 17 00:00:00 2001 From: "taha@asks2" Date: Sun, 23 Jan 2022 21:56:15 +0100 Subject: [PATCH] Added script that converts git submodules to regular git repos. Last used on /media/bay/taha/projects/ansible/roles/public with the script located in the root of that directory, and invoked as: ``` ./submodule-to-repo.sh tailscale ``` --- chertex.sh | 3 ++- submodule-to-repo.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 submodule-to-repo.sh diff --git a/chertex.sh b/chertex.sh index add98a4..950c83e 100755 --- a/chertex.sh +++ b/chertex.sh @@ -449,7 +449,8 @@ runtime=$(( $endtime - $starttime )) # send push message via Gotify CLI # if runtime is longer than X minutes (suitable limit perhaps 3 min) if (( $runtime > 180 )); then - gotify push --quiet --title "$dir_wd" --priority 5 "chertex.sh $@ \nCompleted in $runtime s" + gotify push --quiet --title "$dir_wd" --priority 5 "chertex.sh $@ \nCompleted in $runtime s" + msg "Push notification sent to Gotify" fi msg "${On_Cyan}-------------------------------------${NOFORMAT}" diff --git a/submodule-to-repo.sh b/submodule-to-repo.sh new file mode 100755 index 0000000..097f930 --- /dev/null +++ b/submodule-to-repo.sh @@ -0,0 +1,59 @@ +#!/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