On Sat, Jan 19, 2019 at 12:16:26PM -0800, Victor Toni wrote:

> Doing open source work (mostly via GitHub) and having an automatic setup 
> for work (installer which can put the IDE and source anywhere) I sometimes 
> end up having my public email address and and my work address mixed up on 
> commits.
> 
> I tried to group my public activities in a common directory and work 
> rrealted repositories in another but this is not always feasible.
> So my git setup which is based on directories does not work out in same 
> case.
> 
> Is it possible to assign "user.email" based on remotes? This would seem to 
> solve my problems.
> (I know that it might get confusing when using multiple remotes on the same 
> repository, but this is something I do only as an exception...)
> 

I'm not sure it's possible to achieve _exactly_ what you're after, but I
think it's perfectly possible to get you halfway there.

You could create a pre-commit hook which would roll like this:
1) If HEAD does not point to a branch, do nothing.
2) If HEAD points to a branch, read its remote. If none is configured,
   do nothing.
3) Obtain the url of the remote and compare it against a list of
   "known" remotes. Act on the result.

The crux is the check in (3): say, you configure your identity to be
associated with your $dayjob, and then have the check see whether the
remote is not your $dayjob's host(s). If so, the hook would print a
warning message telling you what's the problem and quit with a non-zero
exit code to abort creation of a commit. You would then recommit while
overriding GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables —
like in

  $ GIT_AUTHOR_NAME=foo GIT_AUTHOR_EMAIL=bar git commit ...

or using the "-c" command-line option to the "umbrella" git command:

  $ git -c author.name=foo -c author.email=bar commit ...

You could have a special Git alias to do one of the above like, I dunno,
`git foss-commit` ;-)

The commands you'd need for such a hook script, are: `git symbolic-ref`,
and `git config`.

-- 
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.

Reply via email to