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 ```master
							parent
							
								
									2db7a877c8
								
							
						
					
					
						commit
						2aded2bfc5
					
				| @ -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 | ||||
					Loading…
					
					
				
		Reference in New Issue