threads / patch / 38331

patchgit-svn: make it play nicely with submodules

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

## tl;dr

3 messages between Jan 10, 2015 and Jan 10, 2015. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Ramkumar Ramachandra· Jan 10, 2015, 14:55 UTC · lore
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(+)
Show changes to git-svn.perl +4 −0
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· Jan 10, 2015, 22:11 UTC · re: Ramkumar Ramachandra · lore

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

Ramkumar Ramachandra <artagnon@gmail.com> wrote:
Show 9 quoted lines
> +++ 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· Jan 10, 2015, 22:13 UTC · re: Eric Wong · lore

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

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.

← back to recent threads