git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* how to access working tree from .git dir?
@ 2007-09-06 23:20 Josh England
  2007-09-07 20:43 ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Josh England @ 2007-09-06 23:20 UTC (permalink / raw)
  To: Git Mailing List

In messsing around with hooks, I've discovered that not all hooks are
run in the same environment.  In particular, the current working
directory in the post-receive hook (maybe others as well) is the GIT_DIR
(.git) directory, instead of the root of the working tree (as in
pre-commit).

This wouldn't be so bad, but it seems that `git rev-parse --show-cdup`
does not show anything valid if your current working directory is inside
the .git dir.  This creates a scenario where there is no consistent way
to access the root of the working tree from within a hook.  To make
things worse, the behavior changes subtly whether $GIT_DIR is defined or
not.

I've got a patch that changes the current working directory before
calling the post-receive hook, but that's more of a workaround than a
fix.  I'd like to be able to run `git rev-parse --show-cdup` from with
a .git directory and have it produce a valid result.

So:  I'm poking around around and trying to find the right answer but
some things look weird.  If anyone knows the quick-and-easy answer here
please let me know.  Otherwise, I'll continue to poke around some more.

Thanks,

-JE

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-06 23:20 how to access working tree from .git dir? Josh England
@ 2007-09-07 20:43 ` Junio C Hamano
  2007-09-07 21:27   ` Josh England
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-09-07 20:43 UTC (permalink / raw)
  To: Josh England; +Cc: Git Mailing List

"Josh England" <jjengla@sandia.gov> writes:

> In messsing around with hooks, I've discovered that not all hooks are
> run in the same environment.  In particular, the current working
> directory in the post-receive hook (maybe others as well) is the GIT_DIR
> (.git) directory, instead of the root of the working tree (as in
> pre-commit).

It is not even "instead of"; that's the only sane thing to do
for post-receive, which is in response to git-push and usually
used for a bare repository, i.e. without any work tree.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 20:43 ` Junio C Hamano
@ 2007-09-07 21:27   ` Josh England
  2007-09-07 21:44     ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Josh England @ 2007-09-07 21:27 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Fri, 2007-09-07 at 13:43 -0700, Junio C Hamano wrote:
> "Josh England" <jjengla@sandia.gov> writes:
> 
> > In messsing around with hooks, I've discovered that not all hooks are
> > run in the same environment.  In particular, the current working
> > directory in the post-receive hook (maybe others as well) is the GIT_DIR
> > (.git) directory, instead of the root of the working tree (as in
> > pre-commit).
> 
> It is not even "instead of"; that's the only sane thing to do
> for post-receive, which is in response to git-push and usually
> used for a bare repository, i.e. without any work tree.

I thought there was probably a sane reason for it.  That is perfectly
acceptable, but the problem still exists that there doesn't seem to be a
good way to access the top of the working tree from within the GIT_DIR.
Since I now know that post-receive has a CWD in .git, I could just use
`pwd`/../ , but I was hoping for a better (read: consistent between
hooks) solution.

-JE

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 21:27   ` Josh England
@ 2007-09-07 21:44     ` Junio C Hamano
  2007-09-07 22:11       ` Josh England
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-09-07 21:44 UTC (permalink / raw)
  To: Josh England; +Cc: Git Mailing List

Josh England <jjengla@comcast.net> writes:

> ... there doesn't seem to be a
> good way to access the top of the working tree from within the GIT_DIR.
> Since I now know that post-receive has a CWD in .git, I could just use
> `pwd`/../ , but I was hoping for a better (read: consistent between
> hooks) solution.

I do not think it is a bad thing for _your_ script to have the
knowledge that in _your_ repositories everywhere, the top of the
work tree is $GIT_DIR/.. and there is no repository that lacks a
work tree.  Obviously that would not work for people with bare
repositories, but they would not be using _your_ script in their
bare repositories, so that is Ok.

You can also configure core.worktree in $GIT_DIR/config and use
that from the hook script, I presume, although I haven't done it
(and do not see a need to do so) myself yet.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 21:44     ` Junio C Hamano
@ 2007-09-07 22:11       ` Josh England
  2007-09-07 22:12         ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Josh England @ 2007-09-07 22:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Fri, 2007-09-07 at 14:44 -0700, Junio C Hamano wrote:
> Josh England <jjengla@comcast.net> writes:
> 
> > ... there doesn't seem to be a
> > good way to access the top of the working tree from within the GIT_DIR.
> > Since I now know that post-receive has a CWD in .git, I could just use
> > `pwd`/../ , but I was hoping for a better (read: consistent between
> > hooks) solution.
> 
> I do not think it is a bad thing for _your_ script to have the
> knowledge that in _your_ repositories everywhere, the top of the
> work tree is $GIT_DIR/.. and there is no repository that lacks a
> work tree.  Obviously that would not work for people with bare
> repositories, but they would not be using _your_ script in their
> bare repositories, so that is Ok.

OK. Fair enough.  Maybe it would be good to note in git-sh-setup.sh that
many of the supplied functions will not work when called from within
$GIT_DIR.

-JE

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 22:11       ` Josh England
@ 2007-09-07 22:12         ` Junio C Hamano
  2007-09-07 22:34           ` Josh England
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-09-07 22:12 UTC (permalink / raw)
  To: Josh England; +Cc: Git Mailing List

Josh England <jjengla@comcast.net> writes:

> OK. Fair enough.  Maybe it would be good to note in git-sh-setup.sh that
> many of the supplied functions will not work when called from within
> $GIT_DIR.

Sorry, "supplied functions"?  Care to clarify with a patch?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 22:12         ` Junio C Hamano
@ 2007-09-07 22:34           ` Josh England
  2007-09-07 23:42             ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Josh England @ 2007-09-07 22:34 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Fri, 2007-09-07 at 15:12 -0700, Junio C Hamano wrote:
> Josh England <jjengla@comcast.net> writes:
> 
> > OK. Fair enough.  Maybe it would be good to note in git-sh-setup.sh that
> > many of the supplied functions will not work when called from within
> > $GIT_DIR.
> 
> Sorry, "supplied functions"?  Care to clarify with a patch?

I guess really just the cd_to_topdir() function.  It will silently fail
when run from within $GIT_DIR.

-JE

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 22:34           ` Josh England
@ 2007-09-07 23:42             ` Junio C Hamano
  2007-09-08  1:02               ` Josh England
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-09-07 23:42 UTC (permalink / raw)
  To: Josh England; +Cc: Git Mailing List

Josh England <jjengla@comcast.net> writes:

> On Fri, 2007-09-07 at 15:12 -0700, Junio C Hamano wrote:
>> Josh England <jjengla@comcast.net> writes:
>> 
>> > OK. Fair enough.  Maybe it would be good to note in git-sh-setup.sh that
>> > many of the supplied functions will not work when called from within
>> > $GIT_DIR.
>> 
>> Sorry, "supplied functions"?  Care to clarify with a patch?
>
> I guess really just the cd_to_topdir() function.  It will silently fail
> when run from within $GIT_DIR.

Ah, I see what you meant.

I think you probably are supposed to check with is_bare_repository
or something before calling that, as asking to cd to toplevel
implies you know there is such a thing as toplevel ;-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to access working tree from .git dir?
  2007-09-07 23:42             ` Junio C Hamano
@ 2007-09-08  1:02               ` Josh England
  0 siblings, 0 replies; 9+ messages in thread
From: Josh England @ 2007-09-08  1:02 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Fri, 2007-09-07 at 16:42 -0700, Junio C Hamano wrote:
> Josh England <jjengla@comcast.net> writes:
> 
> > On Fri, 2007-09-07 at 15:12 -0700, Junio C Hamano wrote:
> >> Josh England <jjengla@comcast.net> writes:
> >> 
> >> > OK. Fair enough.  Maybe it would be good to note in git-sh-setup.sh that
> >> > many of the supplied functions will not work when called from within
> >> > $GIT_DIR.
> >> 
> >> Sorry, "supplied functions"?  Care to clarify with a patch?
> >
> > I guess really just the cd_to_topdir() function.  It will silently fail
> > when run from within $GIT_DIR.
> 
> Ah, I see what you meant.
> 
> I think you probably are supposed to check with is_bare_repository
> or something before calling that, as asking to cd to toplevel
> implies you know there is such a thing as toplevel ;-)

That's fine.  I guess using `$GIT_DIR/../` as you mentioned before will
just have to work.

-JE

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-09-08  1:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-06 23:20 how to access working tree from .git dir? Josh England
2007-09-07 20:43 ` Junio C Hamano
2007-09-07 21:27   ` Josh England
2007-09-07 21:44     ` Junio C Hamano
2007-09-07 22:11       ` Josh England
2007-09-07 22:12         ` Junio C Hamano
2007-09-07 22:34           ` Josh England
2007-09-07 23:42             ` Junio C Hamano
2007-09-08  1:02               ` Josh England

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).