Re: [PATCH v7 1/2] submodule: prevent overwriting .gitmodules entry on path reuse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
> +	}




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux