0

I've setup a Git server according to this page.

I've also incorporated a post-receive hook according to this page.

I'm using GitHub for Windows to communicate between my local machine and the git repo.

My issue is that the post-receive hook utilizes a variable found in git config user.asana-key. I've set that variable on my local machine. However, when I commit to the server repository, that value is empty.

I'm wondering if there's something specific I should be doing to send this variable along with the git commit so that the hook can read it?
And if there's someway to automate this to be sent with every single commit?

EDIT:

I have since learned that these config variables are never sent to the server with a commit normally. So my question at this point becomes is there a way to send these variables, or is there way inside the post-receive hook to set the key based on the user.email attached to the commit?

Arak Tai'Roth
  • 408
  • 1
  • 7
  • 24

2 Answers2

0

Do I understand you right that you want git configuration to be updated on the server with each push?

Git configuration is not cloned and versioned in any way. And git hook on the server side certainly reads the server configuration. But you could make a simple automation:

  • a txt file with user.asana-key value in your repo
  • a post-receive hook to read updated value and run git config --local user.asana-key <value>

Or, if there are many users and you need to send individual keys as parameters for each commit - this won't work.

Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
  • There are 2 users, so it would be helpful to have this local to their machine if at all possible. I'm not quite sure I understand why it can't be on the local machine. As I said I'm using Github for Windows (the GUI client), and it allows me to set user.name and user.email and those get passed through just fine, showing up on the commits I make. – Arak Tai'Roth May 19 '15 at 07:12
  • There is an important difference. user.name and user.email are used *locally* to put information into the commits, which are then pushed. The config variables themselves are never seen by the server. – Jonas Schäfer May 19 '15 at 08:31
  • Ah, alright. So then is there anyway to pass that info during a commit? Or would it be possible inside a git hook (post-receive) to set the key based on the user.email used for the commit? – Arak Tai'Roth May 19 '15 at 08:49
0

I didn't receive an answer on this, so I kept looking around and just posting this for others in case someone runs across this.

I discovered that you can't access the user.name and user.email sent with a commit in the git hooks. So I had to go another way. I installed gitolite on the server with the git repository, following their idiots guide located here. I combined that with their instructions on how to do it with an existing repo, located here. And then followed their guide for using hooks, which explains what variables are passed to hooks, located here. Specifically I used the variable GL_USER.

Then inside the local config for the git repo I added:

[asana]
    gitolite-user-name = asana-api-key

Where gitolite-user-name is the username associated with each gitolite user you have, and asana-api-key is the api key for that user.

Then in my post-receive hook I added:

apikey=$(git config asana.$GL_USER)

Which grabs the corresponding api key for the user that did the commit. This allows each user to comment on their own commits using their account in Asana.

Arak Tai'Roth
  • 408
  • 1
  • 7
  • 24