Skip to contentSkip to conversation

git-svn: make it play nicely with submodules

PATCH In review Ramkumar Ramachandra 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-svn: make it play nicely with submodules

It's a simple matter of opening the directory specified in the gitfile.

---
 git-svn.perl | 4 ++++
 1 file changed, 4 insertions(+)
git-svn.perl +4 -0
index 6aa156c..8642783 100755
@@ -337,6 +337,10 @@ for (my $i = 0; $i < @ARGV; $i++) {
 # make sure we're always running at the top-level working directory
 if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
 	$ENV{GIT_DIR} ||= ".git";
+	# catch the submodule case
+	if (open(my $fh, '<', $ENV{GIT_DIR})) {
+		$ENV{GIT_DIR} = $1 if <$fh> =~ /^gitdir: (.+)$/;
+	}
 } else {
 	my ($git_dir, $cdup);
 	git_cmd_try {
Signature · 1 line
2.2.1
#1 lore raw

git-svn.perl for (my $i = 0; $i < @ARGV; $i++) { · line 343

Quoted 9 lines · Ramkumar Ramachandra

+++ b/git-svn.perl

git-svn.perl +4 -0
@@ -337,6 +337,10 @@ for (my $i = 0; $i < @ARGV; $i++) {
 # make sure we're always running at the top-level working directory
 if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
 	$ENV{GIT_DIR} ||= ".git";
+	# catch the submodule case
+	if (open(my $fh, '<', $ENV{GIT_DIR})) {
+		$ENV{GIT_DIR} = $1 if <$fh> =~ /^gitdir: (.+)$/;
+	}

How portable is open on a directory? Perhaps it'd be better to check if it's a file, first:

	if (-f $ENV{GIT_DIR}) {
		open(my $fh, '<', $ENV{GIT_DIR}) or
			die "failed to open $ENV{GIT_DIR}: $!\n";
		$ENV{GIT_DIR} = $1 if <$fh> =~ /^gitdir: (.+)$/;
	}
#2 lore raw
Quoted 2 lines · Eric Wong

How portable is open on a directory? Perhaps it'd be better to check if it's a file, first:

Sure, that works; feel free to fix it up locally before committing.