Commit e2ea4cae authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Make do_upgrade remove old submodules

parent 9a509268
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -97,11 +97,47 @@ update_worktree()
	if git merge --ff --no-edit $upstream origin/master; then
		git submodule sync --recursive
		git submodule update --init --recursive --depth=1 ${GIT_JOBS}
		foreach_submodule check_submodule
	else
		git reset $original
	fi
}

foreach_submodule()
{
	local name module SUBMODULE
	git config --name-only --list |
	sed -n 's/^submodule\.\(.\+\)\.url$/\1/p' |
	while read name; do
		module=`git rev-parse --git-dir`/modules/$name || return 1

		# remove old leftover modules in config
		if ! [ -d "$module" ]; then
			git config --remove-section submodule."$name"
			continue
		fi

		# get worktree as SUBMODULE for eval
		SUBMODULE=`git config --file $module/config core.worktree`
		SUBMODULE=`cd $module/$SUBMODULE; pwd`

		(eval "$*")
	done
}

check_submodule()
{
	# exit early if status is fine
	git submodule status --quiet -- $SUBMODULE && return

	# If status returns 1 submodule removed from .gitmodules
	if [ $? -eq 1 ]; then
		test -e "$SUBMODULE" && rm -r "$SUBMODULE"
	fi

	git submodule deinit $SUBMODULE
}

do_update()
{
	local timestamp=${HOME}/.shell/.update