зеркало из https://github.com/microsoft/git.git
git-svn: disallow ambigious local refspecs
Having multiple fetch refspecs pointing to the same local ref would be a very bad thing. Start avoiding the use of fatal() or exit() inside the modules so we can libify more easily. Signed-off-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
Родитель
8b8fc06824
Коммит
b805b44a92
40
git-svn.perl
40
git-svn.perl
|
@ -169,7 +169,11 @@ load_authors() if $_authors;
|
||||||
unless ($cmd =~ /^(?:init|rebuild|multi-init|commit-diff)$/) {
|
unless ($cmd =~ /^(?:init|rebuild|multi-init|commit-diff)$/) {
|
||||||
Git::SVN::Migration::migration_check();
|
Git::SVN::Migration::migration_check();
|
||||||
}
|
}
|
||||||
$cmd{$cmd}->[0]->(@ARGV);
|
eval {
|
||||||
|
Git::SVN::verify_remotes_sanity();
|
||||||
|
$cmd{$cmd}->[0]->(@ARGV);
|
||||||
|
};
|
||||||
|
fatal $@ if $@;
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
||||||
####################### primary functions ######################
|
####################### primary functions ######################
|
||||||
|
@ -715,6 +719,22 @@ sub read_all_remotes {
|
||||||
$r;
|
$r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub verify_remotes_sanity {
|
||||||
|
my %seen;
|
||||||
|
foreach (command(qw/config -l/)) {
|
||||||
|
if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
|
||||||
|
if ($seen{$1}) {
|
||||||
|
die "Remote ref refs/remote/$1 is tracked by",
|
||||||
|
"\n \"$_\"\nand\n \"$seen{$1}\"\n",
|
||||||
|
"Please resolve this ambiguity in ",
|
||||||
|
"your git configuration file before ",
|
||||||
|
"continuing\n";
|
||||||
|
}
|
||||||
|
$seen{$1} = $_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# we allow more chars than remotes2config.sh...
|
# we allow more chars than remotes2config.sh...
|
||||||
sub sanitize_remote_name {
|
sub sanitize_remote_name {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
|
@ -727,16 +747,22 @@ sub init {
|
||||||
my $self = _new($class, $repo_id, $ref_id, $path);
|
my $self = _new($class, $repo_id, $ref_id, $path);
|
||||||
if (defined $url) {
|
if (defined $url) {
|
||||||
$url =~ s!/+$!!; # strip trailing slash
|
$url =~ s!/+$!!; # strip trailing slash
|
||||||
|
|
||||||
|
# verify that we aren't overwriting anything:
|
||||||
my $orig_url = eval {
|
my $orig_url = eval {
|
||||||
command_oneline('config', '--get',
|
command_oneline('config', '--get',
|
||||||
"svn-remote.$repo_id.url")
|
"svn-remote.$repo_id.url")
|
||||||
};
|
};
|
||||||
if ($orig_url) {
|
if ($orig_url && ($orig_url ne $url)) {
|
||||||
if ($orig_url ne $url) {
|
die "svn-remote.$repo_id.url already set: ",
|
||||||
die "svn-remote.$repo_id.url already set: ",
|
"$orig_url\nwanted to set to: $url\n";
|
||||||
"$orig_url\nwanted to set to: $url\n";
|
}
|
||||||
}
|
my ($xrepo_id, $xpath) = find_ref($self->refname);
|
||||||
} else {
|
if (defined $xpath) {
|
||||||
|
die "svn-remote.$xrepo_id.fetch already set to track ",
|
||||||
|
"$xpath:refs/remotes/", $self->refname, "\n";
|
||||||
|
}
|
||||||
|
if (!$orig_url) {
|
||||||
command_noisy('config',
|
command_noisy('config',
|
||||||
"svn-remote.$repo_id.url", $url);
|
"svn-remote.$repo_id.url", $url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,4 +215,15 @@ echo tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 >> expected
|
||||||
|
|
||||||
test_expect_success "$name" "diff -u a expected"
|
test_expect_success "$name" "diff -u a expected"
|
||||||
|
|
||||||
|
test_expect_failure 'exit if remote refs are ambigious' "
|
||||||
|
git-repo-config --add svn-remote.git-svn.fetch \
|
||||||
|
bar:refs/remotes/git-svn &&
|
||||||
|
git-svn migrate
|
||||||
|
"
|
||||||
|
test_expect_failure 'exit if init-ing a would clobber a URL' "
|
||||||
|
git-repo-config --unset svn-remote.git-svn.fetch \
|
||||||
|
'^bar:refs/remotes/git-svn$' &&
|
||||||
|
git-svn init $svnrepo/bar
|
||||||
|
"
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Загрузка…
Ссылка в новой задаче