开发者

Making git probe for user before making a commit

We are a developer team that need to work on large machines in the lab. These machines are controlled by PC's where development also takes place. The lab PC's are always run under the same user id. The problem is that we would like git commit messages be associated by the developer user id. One method would be to request each user that comes to a machine manually runs a script that does:

git config user.name Foo baz

but the problem is that this is easily forgotten.

Instead I got the idea that perhaps I can use the git pre-commit hook to probe the user for her id and then run the above command. But unfortunately it doesn't work as it seems like the user.name field has already bee开发者_StackOverflown queried before the pre-commit hook is invoked.

Another ugly idea would be to use the post-commit hook to get the user id, and then to rewrite the last commit message according to the name entered by the user. Would this work?

Does someone have any solution to this problem?


You could store different users' config files in different locations, then write a script to run on login that sets $GIT_CONFIG to point at the user's configuration file. Look at the ENVIRONMENT section of git help config.

Edit: If the user uses the same shell as someone else, you could write a wrapper around git that prompts the user, sets the environment variable, then runs the real git.


What I did was create the global config user.name to be:

git config user.name CONFIGUREMEINTHELOCALREPOxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Which, at least for my version of git (1.7.5.3), is a 968 byte long value which can be set but which never will be allowed to commit. fatal: Impossibly long personal identifier

You can then ask the user to set the environmental variables(1) and/or local git config variables to a sane value which will allow a commit.

Yes, this too assumes the user will create a new session (environmental variables) or have a private repo (local config). If people are sharing the same session (walking up to an unsecured pre-logged in console) I think you are probably mostly out of luck, though you can try to have $PROMPT_COMMAND check for idle-time and unset the variables or something like that, or use $TMOUT to autologout.

(1) Environmental variables in question:

       $GIT_AUTHOR_NAME
       $GIT_AUTHOR_EMAIL
       $GIT_COMMITTER_NAME
       $GIT_COMMITTER_EMAIL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜