* [RFC PATCH] git-svn: proper detection of bare repositories
@ 2008-11-03 0:09 Deskin Miller
2008-11-04 8:30 ` Eric Wong
0 siblings, 1 reply; 4+ messages in thread
From: Deskin Miller @ 2008-11-03 0:09 UTC (permalink / raw)
To: git; +Cc: normalperson
I keep coming across commands like this, which don't work properly in bare
repositories, and thinking that they need to be patched (see e.g. ddff8563, or
Duy's comments on the thread starting at
http://thread.gmane.org/gmane.comp.version-control.git/98849), but now I'm not
so sure. For one, despite this patch working, it turns out that 'git --bare
svn <cmd>' also works (and presumably has) for some time.
Is git --bare the correct way to deal with this situation? That is to say, do
we intend commands to 'just work' regardless of whether the repo is bare or
not, or should the user be thinking about the difference and including --bare
in the command invocation when necessary? I'm a vote for the 'just work' camp,
but it seems a lot of things aren't necessarily that way. On the other hand,
the majority of commands do just work.
I guess I'm asking for a sanity check before I write any more such patches;
certainly I find them useful, as the issues come up during my normal use of
Git, but I don't want to be pursuing things of no use to anyone else, or
(worse) things that are fundamentally wrong for some reason I don't understand
yet.
-- 8< --
When in a bare repository (or .git, for that matter), git-svn would fail
to initialise properly, since git rev-parse --show-cdup would not output
anything. However, git rev-parse --show-cdup actually returns an error
code if it's really not in a git directory.
Fix the issue by checking for an explicit error from git rev-parse, and
setting $git_dir appropriately if instead it just does not output.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
---
git-svn.perl | 14 ++++++++++----
t/t9100-git-svn-basic.sh | 9 +++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 56238da..d25e9be 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -42,6 +42,7 @@ use File::Path qw/mkpath/;
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
use IPC::Open3;
use Git;
+use Error qw/:try/;
BEGIN {
# import functions from Git into our packages, en masse
@@ -214,11 +215,16 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
"but it is not a directory\n";
}
my $git_dir = delete $ENV{GIT_DIR};
- chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
- unless (length $cdup) {
- die "Already at toplevel, but $git_dir ",
- "not found '$cdup'\n";
- }
+ my $cdup = undef;
+ try {
+ $cdup = command_oneline(qw/rev-parse --show-cdup/);
+ $git_dir = '.' unless ($cdup);
+ chomp $cdup if ($cdup);
+ $cdup = "." unless ($cdup && length $cdup);
+ }
+ catch Git::Error::Command with {
+ die "Already at toplevel, but $git_dir not found\n";
+ };
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
unless (-d $git_dir) {
die "$git_dir still not found after going to ",
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index 843a501..fdbc23a 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' "
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
"
+test_expect_success 'git-svn works in a bare repository' '
+ mkdir bare-repo &&
+ ( cd bare-repo &&
+ git init --bare &&
+ GIT_DIR=. git svn init "$svnrepo" &&
+ git svn fetch ) &&
+ rm -rf bare-repo
+ '
+
test_done
--
1.6.0.3.524.g47d14
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [RFC PATCH] git-svn: proper detection of bare repositories
2008-11-03 0:09 [RFC PATCH] git-svn: proper detection of bare repositories Deskin Miller
@ 2008-11-04 8:30 ` Eric Wong
2008-11-06 5:07 ` [PATCH v2] " Deskin Miller
0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2008-11-04 8:30 UTC (permalink / raw)
To: Deskin Miller; +Cc: git
Deskin Miller <deskinm@umich.edu> wrote:
> I keep coming across commands like this, which don't work properly in bare
> repositories, and thinking that they need to be patched (see e.g. ddff8563, or
> Duy's comments on the thread starting at
> http://thread.gmane.org/gmane.comp.version-control.git/98849), but now I'm not
> so sure. For one, despite this patch working, it turns out that 'git --bare
> svn <cmd>' also works (and presumably has) for some time.
Interesting. I've never even looked at --bare myself. It always
should've worked if GIT_DIR= was explicitly set and I guess back in the
old days when I wrote git-svn, --bare wasn't even a flag :)
> Is git --bare the correct way to deal with this situation? That is to say, do
> we intend commands to 'just work' regardless of whether the repo is bare or
> not, or should the user be thinking about the difference and including --bare
> in the command invocation when necessary? I'm a vote for the 'just work' camp,
> but it seems a lot of things aren't necessarily that way. On the other hand,
> the majority of commands do just work.
>
> I guess I'm asking for a sanity check before I write any more such patches;
> certainly I find them useful, as the issues come up during my normal use of
> Git, but I don't want to be pursuing things of no use to anyone else, or
> (worse) things that are fundamentally wrong for some reason I don't understand
> yet.
I don't think there's anything fundamentally wrong with things 'just
working' on bare repos. It's just another case of something that not
many people end up using (especially for git-svn) and hence got fewer
testers and bug reports.
> -- 8< --
>
> When in a bare repository (or .git, for that matter), git-svn would fail
> to initialise properly, since git rev-parse --show-cdup would not output
> anything. However, git rev-parse --show-cdup actually returns an error
> code if it's really not in a git directory.
>
> Fix the issue by checking for an explicit error from git rev-parse, and
> setting $git_dir appropriately if instead it just does not output.
>
> Signed-off-by: Deskin Miller <deskinm@umich.edu>
> ---
> git-svn.perl | 14 ++++++++++----
> t/t9100-git-svn-basic.sh | 9 +++++++++
> 2 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/git-svn.perl b/git-svn.perl
> index 56238da..d25e9be 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -42,6 +42,7 @@ use File::Path qw/mkpath/;
> use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
> use IPC::Open3;
> use Git;
> +use Error qw/:try/;
>
> BEGIN {
> # import functions from Git into our packages, en masse
> @@ -214,11 +215,16 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
> "but it is not a directory\n";
> }
> my $git_dir = delete $ENV{GIT_DIR};
> - chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
> - unless (length $cdup) {
> - die "Already at toplevel, but $git_dir ",
> - "not found '$cdup'\n";
> - }
> + my $cdup = undef;
> + try {
> + $cdup = command_oneline(qw/rev-parse --show-cdup/);
> + $git_dir = '.' unless ($cdup);
> + chomp $cdup if ($cdup);
> + $cdup = "." unless ($cdup && length $cdup);
> + }
> + catch Git::Error::Command with {
> + die "Already at toplevel, but $git_dir not found\n";
> + };
How about using git_cmd_try instead?
The Error.pm try/catch stuff makes me a bit uncomfortable. I realize
it's (unfortunately) in Git.pm; but I'd rather keep it confined there so
we can more easily remove it later if someone were inclined.
Otherwise I like the idea of this patch.
Thanks,
--
Eric Wong
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2] git-svn: proper detection of bare repositories
2008-11-04 8:30 ` Eric Wong
@ 2008-11-06 5:07 ` Deskin Miller
2008-11-06 9:45 ` Eric Wong
0 siblings, 1 reply; 4+ messages in thread
From: Deskin Miller @ 2008-11-06 5:07 UTC (permalink / raw)
To: Eric Wong; +Cc: git, gitster
On Tue, Nov 04, 2008 at 12:30:15AM -0800, Eric Wong wrote:
> How about using git_cmd_try instead?
>
> The Error.pm try/catch stuff makes me a bit uncomfortable. I realize
> it's (unfortunately) in Git.pm; but I'd rather keep it confined there so
> we can more easily remove it later if someone were inclined.
Yeah, major thinko; I read the Git(3pm) manpage, looked at git_cmd_try, and for
some reason thought that it wasn't what I want. But it's exactly what I want.
Deskin Miller
-- 8< --
When in a bare repository (or .git, for that matter), git-svn would fail
to initialise properly, since git rev-parse --show-cdup would not output
anything. However, git rev-parse --show-cdup actually returns an error
code if it's really not in a git directory.
Fix the issue by checking for an explicit error from git rev-parse, and
setting $git_dir appropriately if instead it just does not output.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
---
git-svn.perl | 12 +++++++-----
t/t9100-git-svn-basic.sh | 9 +++++++++
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 56238da..829a323 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -214,11 +214,13 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
"but it is not a directory\n";
}
my $git_dir = delete $ENV{GIT_DIR};
- chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/));
- unless (length $cdup) {
- die "Already at toplevel, but $git_dir ",
- "not found '$cdup'\n";
- }
+ my $cdup = undef;
+ git_cmd_try {
+ $cdup = command_oneline(qw/rev-parse --show-cdup/);
+ $git_dir = '.' unless ($cdup);
+ chomp $cdup if ($cdup);
+ $cdup = "." unless ($cdup && length $cdup);
+ } "Already at toplevel, but $git_dir not found\n";
chdir $cdup or die "Unable to chdir up to '$cdup'\n";
unless (-d $git_dir) {
die "$git_dir still not found after going to ",
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index 843a501..fdbc23a 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' "
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
"
+test_expect_success 'git-svn works in a bare repository' '
+ mkdir bare-repo &&
+ ( cd bare-repo &&
+ git init --bare &&
+ GIT_DIR=. git svn init "$svnrepo" &&
+ git svn fetch ) &&
+ rm -rf bare-repo
+ '
+
test_done
--
1.6.0.3.524.g47d14
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] git-svn: proper detection of bare repositories
2008-11-06 5:07 ` [PATCH v2] " Deskin Miller
@ 2008-11-06 9:45 ` Eric Wong
0 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2008-11-06 9:45 UTC (permalink / raw)
To: Deskin Miller; +Cc: git, gitster
Deskin Miller <deskinm@umich.edu> wrote:
> On Tue, Nov 04, 2008 at 12:30:15AM -0800, Eric Wong wrote:
> > How about using git_cmd_try instead?
> >
> > The Error.pm try/catch stuff makes me a bit uncomfortable. I realize
> > it's (unfortunately) in Git.pm; but I'd rather keep it confined there so
> > we can more easily remove it later if someone were inclined.
>
> Yeah, major thinko; I read the Git(3pm) manpage, looked at git_cmd_try, and for
> some reason thought that it wasn't what I want. But it's exactly what I want.
Thanks, acked and pushed out to git://git.bogomips.org/git-svn.git
--
Eric Wong
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-11-06 9:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-03 0:09 [RFC PATCH] git-svn: proper detection of bare repositories Deskin Miller
2008-11-04 8:30 ` Eric Wong
2008-11-06 5:07 ` [PATCH v2] " Deskin Miller
2008-11-06 9:45 ` Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).