2

I wrote the following bash function which should create a commit with my username hardcoded. Yes I know about git config, this is just a minimal example to demonstrate the problem I'm having.

# lib.sh
function lock-commit() {
    local commit_author="Varun Madiath <[email protected]>"
    git commit --author="${commit_author}" "$@"
}

However when I run this, it gives me the error below. Running the command on the command line directly does not result in the error.

[vmadiath@magma ac-test]$ source lib.sh
[vmadiath@magma ac-test]$ lock-commit -m "test"

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <[email protected]>) not allowed

Given that I'm explicitly passing the author, I shouldn't need to set the user.email and user.name config settings.

Any idea why this is happening, and how I can correct this behaviour.

4
  • It works for me. Try cutting your script down to just calling lock-function or showing your whole script or at least how you're calling lock-function. Commented Nov 4, 2015 at 20:28
  • Also, what version of Git are you using? I believe --author hasn't always been there. Commented Nov 4, 2015 at 20:30
  • I'm using git version 2.6.2. I've updated the example without my wrapper scrpit so that I'm calling the function directly. Commented Nov 4, 2015 at 20:40
  • Nope, still can't replicate it with 2.6.2. Are you sure git is git and not some wrapper? Also check there's no git-commit in your PATH. Finally, maybe post your ~/.gitconfig and .git/config. Commented Nov 4, 2015 at 21:01

1 Answer 1

1

Git records two details for each commit: the author (which is what you're overriding) and the committer (which is what it's looking for in your settings).

This allows one user to commit changes on behalf of another, while recording details of both users in the repository.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this had me figure it out. Turns out lib.sh also overrode the HOME variable, which was causing git to not find my settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.