feat(add-git-folder): validate branch before adding submodule

- Check if the target repository is on the expected branch before proceeding
- Exit with error if branch mismatch is detected
- Improve reliability of submodule addition by enforcing branch consistency
This commit is contained in:
Janik von Rotz committed 2026-06-16 09:30:51 +02:00
1 parent e05c215170
commit db90606f7f
1 file changed
+5 -2
+5 -2
View File
@@ -17,8 +17,11 @@ add-git-folder() {
local branch="$2"
local path="$3"
# Clone the repo
git clone -b "$branch" "$url" "$path"
local current_branch=$(git -C "$path" rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" != "$branch" ]]; then
echo "Error: Repository is on branch '$current_branch', expected '$branch'"
exit 1
fi
# Add entry to .gitmodules
git config -f .gitmodules submodule."$path".path "$path"