153
usage
154
fi
155
156
- case "$repo" in
157
- ./*|../*)
158
- # dereference source url relative to parent's url
159
- realrepo="$(resolve_relative_url $repo)" ;;
160
- *)
161
- # Turn the source into an absolute path if
162
- # it is local
163
- if base=$(get_repo_base "$repo"); then
164
- repo="$base"
165
- fi
166
- realrepo=$repo
167
- ;;
168
- esac
169
-
156
# Guess path from repo if not specified or strip trailing slashes
157
if test -z "$path"; then
158
path=$(echo "$repo" | sed -e 's|/*$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
160
path=$(echo "$path" | sed -e 's|/*$||')
161
fi
162
177
- test -e "$path" &&
178
- die "'$path' already exists"
179
-
163
git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
164
die "'$path' already exists in the index"
165
183
- module_clone "$path" "$realrepo" || exit
184
- (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
185
- die "Unable to checkout submodule '$path'"
166
+ # perhaps the path exists and is already a git repo, else clone it
167
+ if test -e "$path"
168
+ then
169
+ if test -d "$path/.git" &&
170
+ test "$(unset GIT_DIR; cd $path; git rev-parse --git-dir)" = ".git"
171
+ then
172
+ echo "Adding existing repo at '$path' to the index"
173
+ else
174
+ die "'$path' already exists and is not a valid git repo"
175
+ fi
176
+ else
177
+ case "$repo" in
178
+ ./*|../*)
179
+ # dereference source url relative to parent's url
180
+ realrepo="$(resolve_relative_url $repo)" ;;
181
+ *)
182
+ # Turn the source into an absolute path if
183
+ # it is local
184
+ if base=$(get_repo_base "$repo"); then
185
+ repo="$base"
186
+ fi
187
+ realrepo=$repo
188
+ ;;
189
+ esac
190
+
191
+ module_clone "$path" "$realrepo" || exit
192
+ (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
193
+ die "Unable to checkout submodule '$path'"
194
+ fi
195
+
196
git add "$path" ||
197
die "Failed to add submodule '$path'"
198