frace / git-passport

A Git command and hook written in Python to manage multiple Git accounts / user identities.
https://github.com/frace/git-passport
Other
109 stars 25 forks source link

pre-commit not called during git init #30

Open holocronweaver opened 9 years ago

holocronweaver commented 9 years ago

I tried git 1.9.* (several subversions) and 2.2.2, and none triggered the pre-commit hook during git init. The hooks were successfully copied from the templates folder, and triggered successfully when I tried to commit, but the README gives the impression a simple git init should trigger pre-commit. Is this a change in more recent git versions? If so, is there a hook that runs during git init, or is some other hook or method necessary?

frace commented 9 years ago

That's the intended behaviour - git init doesn't trigger the git-passport hook since it is a pre-commit hook. All git init does is to copy templates to the local .git directory of a git repository. Then on the first commit the hook gets triggered and lets you select a passport. Alternatively you can just call git passport -s inside that repository to select a passport.

From git init --help:

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates (or to move the repository to another place if --separate-git-dir is given).

Do you think I should describe the procedure more clearly in the README?

holocronweaver commented 9 years ago

Thanks for the clarification. Maybe a couple examples showing the alternative ways to use the library would make things crystal clear for new users, especially for those like me who have little experience with git hooks.

Something like:

cd /my/get/repo
git passport

and

cd /my/git/repo
git init              # Only necessary if repo existed prior to passport installation.
... do some work and stage files for commit  ...
git commit -m 'If you set up hooks correctly, this will trigger passport before committing.'

Also, giving at least one usage example near the top give visitors a quick taste of what git passport offers.