mirror of
https://github.com/git/git.git
synced 2026-01-10 01:56:42 +00:00
Merge branch 'jk/remote-avoid-overlapping-names'
"git remote" now detects remote names that overlap with each other (e.g., remote nickname "outer" and "outer/inner" are used at the same time), as it will lead to overlapping remote-tracking branches. * jk/remote-avoid-overlapping-names: remote: detect collisions in remote names
This commit is contained in:
@@ -157,6 +157,21 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_remote_collision(struct remote *remote, void *data)
|
||||
{
|
||||
const char *name = data;
|
||||
const char *p;
|
||||
|
||||
if (skip_prefix(name, remote->name, &p) && *p == '/')
|
||||
die(_("remote name '%s' is a subset of existing remote '%s'"),
|
||||
name, remote->name);
|
||||
if (skip_prefix(remote->name, name, &p) && *p == '/')
|
||||
die(_("remote name '%s' is a superset of existing remote '%s'"),
|
||||
name, remote->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add(int argc, const char **argv, const char *prefix,
|
||||
struct repository *repo UNUSED)
|
||||
{
|
||||
@@ -208,6 +223,8 @@ static int add(int argc, const char **argv, const char *prefix,
|
||||
if (!valid_remote_name(name))
|
||||
die(_("'%s' is not a valid remote name"), name);
|
||||
|
||||
for_each_remote(check_remote_collision, (void *)name);
|
||||
|
||||
strbuf_addf(&buf, "remote.%s.url", name);
|
||||
git_config_set(buf.buf, url);
|
||||
|
||||
|
||||
@@ -1644,4 +1644,18 @@ test_expect_success 'empty config clears remote.*.pushurl list' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'forbid adding subset of existing remote' '
|
||||
test_when_finished "git remote rm outer" &&
|
||||
git remote add outer url &&
|
||||
test_must_fail git remote add outer/inner url 2>err &&
|
||||
test_grep ".outer/inner. is a subset of existing remote .outer." err
|
||||
'
|
||||
|
||||
test_expect_success 'forbid adding superset of existing remote' '
|
||||
test_when_finished "git remote rm outer/inner" &&
|
||||
git remote add outer/inner url &&
|
||||
test_must_fail git remote add outer url 2>err &&
|
||||
test_grep ".outer. is a superset of existing remote .outer/inner." err
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user