K Jayatheerth <jayatheerthkulkarni2005@xxxxxxxxx> writes: > @@ -3546,6 +3550,29 @@ static int module_add(int argc, const char **argv, const char *prefix, > if(!add_data.sm_name) > add_data.sm_name = add_data.sm_path; > > + existing = submodule_from_name(the_repository, > + null_oid(the_hash_algo), > + add_data.sm_name); > + > + if (existing && strcmp(existing->path, add_data.sm_path)) { Looks quite straight-forward to me. Great. > + if (!force) { > + die(_("submodule name '%s' already used for path '%s'"), > + add_data.sm_name, existing->path); > + } > + > + /* --force: build <name><n> until unique */ > + for (i = 1; ; i++) { > + strbuf_reset(&buf); > + strbuf_addf(&buf, "%s%d", add_data.sm_name, i); > + if (!submodule_from_name(the_repository, > + null_oid(the_hash_algo), > + buf.buf)) { > + break; > + } > + } > + > + add_data.sm_name = sm_name_to_free = strbuf_detach(&buf, NULL); > + }