@matheusbsbs / matheus-bagliano / commits / b805b44a92
Fork 0

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>

Eric Wong committed Jan 22, 2007 at 13:52 UTC b805b44a923e32251af1abd4e8d7bf5f7d4d8ef6
2 files changed +44 -7
git-svn.perl
+33 -7
@@ -169,7 +169,11 @@ load_authors() if $_authors;
169 unless ($cmd =~ /^(?:init|rebuild|multi-init|commit-diff)$/) {
170 Git::SVN::Migration::migration_check();
171 }
172 -$cmd{$cmd}->[0]->(@ARGV);
172 +eval {
173 + Git::SVN::verify_remotes_sanity();
174 + $cmd{$cmd}->[0]->(@ARGV);
175 +};
176 +fatal $@ if $@;
177 exit 0;
178
179 ####################### primary functions ######################
@@ -715,6 +719,22 @@ sub read_all_remotes {
719 $r;
720 }
721
722 +sub verify_remotes_sanity {
723 + my %seen;
724 + foreach (command(qw/config -l/)) {
725 + if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
726 + if ($seen{$1}) {
727 + die "Remote ref refs/remote/$1 is tracked by",
728 + "\n \"$_\"\nand\n \"$seen{$1}\"\n",
729 + "Please resolve this ambiguity in ",
730 + "your git configuration file before ",
731 + "continuing\n";
732 + }
733 + $seen{$1} = $_;
734 + }
735 + }
736 +}
737 +
738 # we allow more chars than remotes2config.sh...
739 sub sanitize_remote_name {
740 my ($name) = @_;
@@ -727,16 +747,22 @@ sub init {
747 my $self = _new($class, $repo_id, $ref_id, $path);
748 if (defined $url) {
749 $url =~ s!/+$!!; # strip trailing slash
750 +
751 + # verify that we aren't overwriting anything:
752 my $orig_url = eval {
753 command_oneline('config', '--get',
754 "svn-remote.$repo_id.url")
755 };
734 - if ($orig_url) {
735 - if ($orig_url ne $url) {
736 - die "svn-remote.$repo_id.url already set: ",
737 - "$orig_url\nwanted to set to: $url\n";
738 - }
739 - } else {
756 + if ($orig_url && ($orig_url ne $url)) {
757 + die "svn-remote.$repo_id.url already set: ",
758 + "$orig_url\nwanted to set to: $url\n";
759 + }
760 + my ($xrepo_id, $xpath) = find_ref($self->refname);
761 + if (defined $xpath) {
762 + die "svn-remote.$xrepo_id.fetch already set to track ",
763 + "$xpath:refs/remotes/", $self->refname, "\n";
764 + }
765 + if (!$orig_url) {
766 command_noisy('config',
767 "svn-remote.$repo_id.url", $url);
768 }
t/t9100-git-svn-basic.sh
+11
@@ -215,4 +215,15 @@ echo tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 >> expected
215
216 test_expect_success "$name" "diff -u a expected"
217
218 +test_expect_failure 'exit if remote refs are ambigious' "
219 + git-repo-config --add svn-remote.git-svn.fetch \
220 + bar:refs/remotes/git-svn &&
221 + git-svn migrate
222 + "
223 +test_expect_failure 'exit if init-ing a would clobber a URL' "
224 + git-repo-config --unset svn-remote.git-svn.fetch \
225 + '^bar:refs/remotes/git-svn$' &&
226 + git-svn init $svnrepo/bar
227 + "
228 +
229 test_done