stoefln
stoefln

Reputation: 14556

Git: how can a team pull and push to the repo from the test server

I guess this is a best-practice question:

We have a test server, a git repository and several workstations. When we do browser tests we work directly on the test server. So whoever does the browser tests, he/she must be able to commit changes from the test server to the repository. Problem is: the git remote (on the test server) specifies a single user for pulling/pushing from/to the repo (in .git/config). Although each team member has a ssh user for the repo.

Question is: how can each user make use of his/her own ssh access for git pulling/pushing?

Upvotes: 2

Views: 333

Answers (2)

Alexander Gladysh
Alexander Gladysh

Reputation: 41403

Try specifying git repo url without username in the clone on the test server (you may change it in config or just clone anew). It will make git use default ssh user name for the host in that url.

Depending on your setup, you may need to additionally modify ~/.ssh/config for each user.

Update

If everyone logs in with the same single user on your test server (a setup that I would not recommend), then it looks like that you have to hack one way or another.

One possible way to do that is this (I did not try it):

If you worry about user.name and user.email, allow test server user to access master git repo and force each user to set GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL (and, maybe, some others) environment variables after login.

It would make sense to do that in some script, just not in .bashrc or similar, for obvious reasons.

To protect yourself from forgetful users, you may want to set up pre-commit hook in git clone where users do their commits to check if the script was called (via environment variable, for example). Alternatively, set up post-receive script on the master git repo, and check there that user credentials in the pushed commits are not that of test server user. In that case users would have to rewrite history to fix commit authors.

If that is not enough, please share more details.

Upvotes: 2

First Zero
First Zero

Reputation: 22356

You can specify the author when committing . Example git commit --author="Author Name <[email protected]>"

A better way, force users to supply an author. In your ~/.bashrc or ~/.profile create the following function -

function gitco() { /usr/local/git/bin/git commit --author="$1"; }

When users commit ask them to run gitco <email address>. Without the email address, gitco will fail.

Example:

gitco [email protected]

Upvotes: 1

Related Questions