Skip Menu |

This queue is for tickets about the Git-Repository CPAN distribution.

Report information
The Basics
Id: 86154
Status: resolved
Priority: 0/
Queue: Git-Repository

People
Owner: Nobody in particular
Requestors: danboo [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.304
Fixed in: (no value)



Subject: 'add' from sub directory give fatal pathspec error
I'm trying to 'add' a file while my current working directory is a sub-directory of the work-tree. This works fine using git directly, but fails when using Git::Repository. Here is a test script that shows the issue. If you comment the 'git add file.txt' line and uncomment the Git::Repository line below it, you should get the failure: fatal: pathspec 'file.txt' did not match any files at -e line 1 Hopefully this isn't just me misusing the module. Thanks! Test Script: set -o errexit set -o xtrace ( rm -rf gittest; true ) mkdir -p gittest/deep echo 1 > gittest/deep/file.txt cd gittest git init git add deep/file.txt git commit -m test1 deep/file.txt cd deep echo 2 > file.txt ## using git directly works, but using Git::Repository fails git add file.txt #perl -MGit::Repository -e 'Git::Repository->new->run( add => q(file.txt) )' git commit -m test2 file.txt git log file.txt
Subject: 'add' from sub directory gives fatal pathspec error
On Fri Jun 14 15:22:27 2013, DANBOO wrote: Show quoted text
> perl -MGit::Repository -e 'Git::Repository->new->run( add => q(file.txt) )'
I found that replacing the above line with this (added 'deep/') works, even though I'm in the 'deep/' directory. perl -MGit::Repository -e 'Git::Repository->new->run( add => q(deep/file.txt) )' Does Git::Repository do a chdir($self->work_tree)? - danboo
Subject: Re: [rt.cpan.org #86154] 'add' from sub directory gives fatal pathspec error
Date: Wed, 19 Jun 2013 16:31:30 +0200
To: "Daniel B. Boorstein via RT" <bug-Git-Repository [...] rt.cpan.org>
From: "Philippe Bruhat (BooK)" <book [...] cpan.org>
On Fri, Jun 14, 2013 at 03:39:07PM -0400, Daniel B. Boorstein via RT wrote: Show quoted text
> Queue: Git-Repository > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=86154 > > > On Fri Jun 14 15:22:27 2013, DANBOO wrote:
> > perl -MGit::Repository -e 'Git::Repository->new->run( add => q(file.txt) )'
> > I found that replacing the above line with this (added 'deep/') works, even though I'm in the 'deep/' directory. > > perl -MGit::Repository -e 'Git::Repository->new->run( add => q(deep/file.txt) )' > > Does Git::Repository do a chdir($self->work_tree)? >
Yes it does. But you can force the cwd for the command (or all commands) with the cwd option. So, running under the 'deep' directory, the following are equivalent: perl -MGit::Repository -e 'Git::Repository->new->run( add => q(deep/file.txt) )' perl -MGit::Repository -e 'Git::Repository->new->run( { cwd => "deep" }, add => q(file.txt) )' Note that cwd option will be used to do a chdir right before the git command is actually run. Relative paths will be relative to the current working dir, not the repository work tree. -- Philippe Bruhat (BooK) Be careful when you take one side or the other. You could wind up in the middle. (Moral from Groo The Wanderer #33 (Epic))
On Wed Jun 19 10:32:20 2013, BOOK wrote: Show quoted text
> Yes it does. But you can force the cwd for the command (or all > commands) > with the cwd option.
Thanks for clarifying. I guess I found it surprising that it didn't let git handle the work-tree discovery, and that a git command could not be simply translated to a Git::Repository command. Looking at the docs again, I couldn't find any mention of the implicit chdir(). Maybe it is worth adding? For my purposes I'll probably just do a { cwd => Cwd::getcwd() } for all commands. Thanks again! - dan
Subject: Re: [rt.cpan.org #86154] 'add' from sub directory give fatal pathspec error
Date: Thu, 20 Jun 2013 00:17:43 +0200
To: "Daniel B. Boorstein via RT" <bug-Git-Repository [...] rt.cpan.org>
From: "Philippe Bruhat (BooK)" <book [...] cpan.org>
On Wed, Jun 19, 2013 at 12:43:05PM -0400, Daniel B. Boorstein via RT wrote: Show quoted text
> > Thanks for clarifying. I guess I found it surprising that it didn't let git > handle the work-tree discovery, and that a git command could not be simply > translated to a Git::Repository command.
Not sure what you mean by "work-tree" discovery. Show quoted text
> Looking at the docs again, I couldn't find any mention of the implicit > chdir(). Maybe it is worth adding?
https://github.com/book/Git-Repository/commit/8b733a486eb0580b985cae6cd50b2ff8189603ec Show quoted text
> For my purposes I'll probably just do a { cwd => Cwd::getcwd() } for all > commands.
I'm wondering if it would be worth adding support for a coderef or just make a special case to mean Cwd::getcwd, so that option could be given to new(), instead of being passed to every command. -- Philippe Bruhat (BooK) Friends are people who are there when you need them. (also applies to dogs) (Moral from Groo The Wanderer #43 (Epic))
On Wed Jun 19 18:18:14 2013, BOOK wrote: Show quoted text
> Not sure what you mean by "work-tree" discovery.
I'm by no means a git expert, so my terminology and understanding may be off. I just mean that in the case of: cd deep/ git add file.txt git walks up the directory tree to find the working root of my repository. I don't have to tell it to chdir or provide a path relative to the root. My point was that if git can already do this, why chdir before invoking git? Not trying to question the choice, I just don't understand the history and reasoning yet. Show quoted text
> https://github.com/book/Git- > Repository/commit/8b733a486eb0580b985cae6cd50b2ff8189603ec
Looks good, thanks! Show quoted text
> I'm wondering if it would be worth adding support for a coderef or > just make a special case to mean Cwd::getcwd, so that option could be > given to new(), instead of being passed to every command.
Those could work. Or to avoid system calls, just allow it to be explicitly disabled with a boolean option like: { chdir => 0 } ## default is { chdir => 1 } Thanks, - danboo
Subject: Re: [rt.cpan.org #86154] 'add' from sub directory give fatal pathspec error
Date: Thu, 20 Jun 2013 01:57:00 +0200
To: "Daniel B. Boorstein via RT" <bug-Git-Repository [...] rt.cpan.org>
From: "Philippe Bruhat (BooK)" <book [...] cpan.org>
On Wed, Jun 19, 2013 at 07:10:21PM -0400, Daniel B. Boorstein via RT wrote: Show quoted text
> Queue: Git-Repository > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=86154 > > > On Wed Jun 19 18:18:14 2013, BOOK wrote:
> > Not sure what you mean by "work-tree" discovery.
> > I'm by no means a git expert, so my terminology and understanding may be off. > I just mean that in the case of: > > cd deep/ > git add file.txt > > git walks up the directory tree to find the working root of my repository. I > don't have to tell it to chdir or provide a path relative to the root. My > point was that if git can already do this, why chdir before invoking git? Not > trying to question the choice, I just don't understand the history and > reasoning yet.
First of all, the use cases (interactive shell usage vs. standalone program) are very different. A user usually has a sense of where he is, while a program deals with paths that may come from anywhere. The logical base for relative paths in this context is the work tree. I remember dealing with git commands that wanted a path relative to the root of the work tree, no matter what the current workding was. The only issue is that I can't remember the command-name, nor could I find it the docs. So maybe I mis-remember. Also, Git::Repository is designed to make it easy to work with several repositories at the same time, at which point it's probably better to not have to worry about where the current directory points to. Show quoted text
> > I'm wondering if it would be worth adding support for a coderef or > > just make a special case to mean Cwd::getcwd, so that option could be > > given to new(), instead of being passed to every command.
> > Those could work. Or to avoid system calls, just allow it to be explicitly disabled with a boolean option like: > > { chdir => 0 } ## default is { chdir => 1 } >
After checking the code, it turns out that System::Command (the base class for Git::Repository::Command, which actually runs the git commands) will not chdir if the cwd option is set to undef. So you can force the "no chdir" behaviour once and for all by creating your object like so: my $r = Git::Repository->new( { cwd => undef } ); And then you do not need to setup the option in every call to run() or command(). Another thing to add to the docs. -- Philippe Bruhat (BooK) The friends we make and the friends we lose are all better than the friends who want to make us lose. (Moral from Groo The Wanderer #1 (Pacific))
On Wed Jun 19 19:57:29 2013, BOOK wrote: Show quoted text
> So you can force the "no chdir" behaviour once and for all by creating > your object like so: > > my $r = Git::Repository->new( { cwd => undef } );
That looks like it will do the trick. Thanks so much for the explanations and discussion. I'll let you close the ticket at your discretion. - danboo