submodules support

This commit is contained in:
2026-03-12 08:58:03 +01:00
parent cf8623bca1
commit e149dac313

15
dot-add
View File

@@ -45,6 +45,21 @@ add_one() {
local REL="${FILE#$HOME/}"
local DEST="$DOTFILES_DIR/$PACKAGE/$REL"
# If the path is a git repo, add it as a submodule instead of moving files
if [[ -d "$FILE/.git" ]]; then
local REMOTE
REMOTE="$(git -C "$FILE" remote get-url origin 2>/dev/null || true)"
if [[ -z "$REMOTE" ]]; then
echo "Error: '$FILE' is a git repo but has no remote origin — can't add as submodule" >&2
return 1
fi
mkdir -p "$(dirname "$DEST")"
rm -rf "$FILE"
git -C "$DOTFILES_DIR" submodule add "$REMOTE" "$PACKAGE/$REL"
echo "Added submodule: $REMOTE -> $DEST"
return 0
fi
mkdir -p "$(dirname "$DEST")"
mv "$FILE" "$DEST"
echo "Moved: $FILE -> $DEST"