Re: [git-users] Git Hooks: How to access the files?
On Wed, Jul 11, 2018 at 02:53:37PM +0200, Jochen Wiedmann wrote: [...] > Is it possible for me to distinguish between a "bare repository" and > the "root of a working tree"? Uh, this is an apples to oranges comparison: a bare repository has no work tree, and a regular repository consists of a work tree and a directory named ".git" and containing the Git object database inside it. So, is your question should instead be read as "how do I tell whether my hook runs in a bare or in a normal repository"? If yes, let's instead start with discussing what type of hook you intend to run; otherwise we may be dragged away by discussing a non-issue (search for the "XY problem" on the 'net). -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] Git Hooks: How to access the files?
Thanks, Konstantin, I'll give your suggestion a try. One followup question, though: Is it possible for me to distinguish between a "bare repository" and the "root of a working tree"? Jochen On Wed, Jul 11, 2018 at 2:44 PM Konstantin Khomoutov wrote: > > On Wed, Jul 11, 2018 at 04:37:25AM -0700, Jochen Wiedmann wrote: > > > I have studied a lot of Git hooks, both simple ones (like the ones, that > > can be found in the "hooks" directory), as well as more complex ones (like > > those running checkstyle), but one question remains unanswered: > > > > Assuming, my git hooks directory is "": Can I > > simply use "../../relative_path_to_file" to access a file in my project > > directory? (The intention being to validate the projects contents in a > > pre-commit, or pre-push hook.) > > Depends on the kind of hook. > > Some hooks are defined to run in the work tree of a non-bare repository. > Namely, hooks which have "commit", "rebase", "patch" etc in their names > are of this kind. > > Still, you should not assume where your Git worktree is located the way > you supposed: Git does some setup before calling its hooks - to cite the > githooks(5) manual: > > | Before Git invokes a hook, it changes its working directory to > | either the root of the working tree in a non-bare repository, or to the > | $GIT_DIR in a bare repository. > > So, when a work-tree related hook runs, the current directory of the > process executing the hook will be the work tree already. > > > More hard-core hooks — such as "[pre-]receive", "[pre-|post-]update" etc > typically run in a server-side bare repository which does not have a > work tree attached. For this kind of hooks, inspecting individual files > is still possible but requires usage of low-level (so-called "plumbing") > Git commands which are able to access the object database of a > repository directly. If you need this, ask a more precise question, and > we will try to help. > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Git for human beings" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/git-users/3sHmGC0IpC8/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > git-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [git-users] Git Hooks: How to access the files?
On Wed, Jul 11, 2018 at 04:37:25AM -0700, Jochen Wiedmann wrote: > I have studied a lot of Git hooks, both simple ones (like the ones, that > can be found in the "hooks" directory), as well as more complex ones (like > those running checkstyle), but one question remains unanswered: > > Assuming, my git hooks directory is "": Can I > simply use "../../relative_path_to_file" to access a file in my project > directory? (The intention being to validate the projects contents in a > pre-commit, or pre-push hook.) Depends on the kind of hook. Some hooks are defined to run in the work tree of a non-bare repository. Namely, hooks which have "commit", "rebase", "patch" etc in their names are of this kind. Still, you should not assume where your Git worktree is located the way you supposed: Git does some setup before calling its hooks - to cite the githooks(5) manual: | Before Git invokes a hook, it changes its working directory to | either the root of the working tree in a non-bare repository, or to the | $GIT_DIR in a bare repository. So, when a work-tree related hook runs, the current directory of the process executing the hook will be the work tree already. More hard-core hooks — such as "[pre-]receive", "[pre-|post-]update" etc typically run in a server-side bare repository which does not have a work tree attached. For this kind of hooks, inspecting individual files is still possible but requires usage of low-level (so-called "plumbing") Git commands which are able to access the object database of a repository directly. If you need this, ask a more precise question, and we will try to help. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[git-users] Git Hooks: How to access the files?
Hi, I have studied a lot of Git hooks, both simple ones (like the ones, that can be found in the "hooks" directory), as well as more complex ones (like those running checkstyle), but one question remains unanswered: Assuming, my git hooks directory is "": Can I simply use "../../relative_path_to_file" to access a file in my project directory? (The intention being to validate the projects contents in a pre-commit, or pre-push hook.) Thanks, Jochen -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.