@matheusbsbs / matheus-bagliano / commits / 5253dc33b7
Fork 0

git-svn: ensure we're at the top-level and can access $GIT_DIR

If we are run inside a subdirectory of a working tree, we'll chdir to the top first before touching anything. This also prevents the accidental creation of .git directories inside subdirectories since they need metadata. Noticed by maio on #git Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Feb 20, 2007 at 01:36 UTC 5253dc33b713e3de63a25305bfc5e966999a0fbe
1 file changed +23
git-svn.perl
+23
@@ -9,6 +9,7 @@ use vars qw/ $AUTHOR $VERSION
9 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
10 $VERSION = '@@GIT_VERSION@@';
11
12 +my $git_dir_user_set = 1 if defined $ENV{GIT_DIR};
13 $ENV{GIT_DIR} ||= '.git';
14 $Git::SVN::default_repo_id = 'svn';
15 $Git::SVN::default_ref_id = $ENV{GIT_SVN_ID} || 'git-svn';
@@ -178,6 +179,28 @@ usage(0) if $_help;
179 version() if $_version;
180 usage(1) unless defined $cmd;
181 load_authors() if $_authors;
182 +
183 +# make sure we're always running
184 +unless ($cmd =~ /(?:clone|init|multi-init)$/) {
185 + unless (-d $ENV{GIT_DIR}) {
186 + if ($git_dir_user_set) {
187 + die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
188 + "but it is not a directory\n";
189 + }
190 + my $git_dir = delete $ENV{GIT_DIR};
191 + chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
192 + unless (length $cdup) {
193 + die "Already at toplevel, but $git_dir ",
194 + "not found '$cdup'\n";
195 + }
196 + chdir $cdup or die "Unable to chdir up to '$cdup'\n";
197 + unless (-d $git_dir) {
198 + die "$git_dir still not found after going to ",
199 + "'$cdup'\n";
200 + }
201 + $ENV{GIT_DIR} = $git_dir;
202 + }
203 +}
204 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
205 Git::SVN::Migration::migration_check();
206 }