# [PATCH] git-svn: make it play nicely with submodules

3 messages from 2015-01-10 to 2015-01-10. Participants: Ramkumar Ramachandra, Eric Wong.
Thread: https://gitlist.dev/t/38331

## Ramkumar Ramachandra, 2015-01-10 14:55

Subject: [PATCH] git-svn: make it play nicely with submodules
Message-ID: <1420901711-81679-1-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1420901711-81679-1-git-send-email-artagnon%40gmail.com

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

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-svn.perl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/git-svn.perl b/git-svn.perl
index 6aa156c..8642783 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -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 {
-- 
2.2.1

```

## Eric Wong, 2015-01-10 22:11

Subject: Re: [PATCH] git-svn: make it play nicely with submodules
Message-ID: <20150110221121.GA30202@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20150110221121.GA30202%40dcvr.yhbt.net
In-Reply-To: <1420901711-81679-1-git-send-email-artagnon@gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> wrote:
> +++ b/git-svn.perl
> @@ -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: (.+)$/;
	}

```

## Ramkumar Ramachandra, 2015-01-10 22:13

Subject: Re: [PATCH] git-svn: make it play nicely with submodules
Message-ID: <CALkWK0kNZyEedL16fru+hWqw7tDz8q3ftQn4=xGUjb2qv8E4SA@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0kNZyEedL16fru%2BhWqw7tDz8q3ftQn4%3DxGUjb2qv8E4SA%40mail.gmail.com
In-Reply-To: <20150110221121.GA30202@dcvr.yhbt.net>

```
Eric Wong wrote:
> 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.

```
