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:
1 file changed
+5
-2
+5
-2
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user