1

I'm putting together a tool to automate some of my git tasks, but I'm running into a problem where "git commit" prompts for user name and password. I can do git add, rm, status ok, but not commit. This is running git via Runtime.exec() from java.

Runtime.getRuntime().exec("git " + cmd, new String[0], mDir);

My current test is on MS Windows. running git commit from the command line works just fine. Only when running via the exec() call does it prompt for user/password.

I did do the git config --global to set both user name and password previously.

So, why is it prompting me?

--Added 2/13

This is with a local git directory, not using a remote repository. Okay, here is the exact error msg that GIT is reporting to me: git commit -F -

 *** 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: unable to auto-detect email address (got 'Cougar@COUGAR-HOUSE.(none)')

2
  • I don't think git will look at user.password by default. It's probably using SSH keys when run at the command line but the environment is different when using exec. Commented Feb 11, 2013 at 15:47
  • Password has nothing to do with Git. If it really does ask for a password, that is connected to your remote authentication (if you're trying to clone, fetch, push or pull) Commented Feb 11, 2013 at 16:04

2 Answers 2

1

Is your HOME environment set in the java runtime? If not, git won't know where to find your global .gitconfig file (normally %HOME%.gitconfig)

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

2 Comments

I think this is the problem. I used exec to run "cmd /c set", and found that it is NOT picking up the default environment that the normal command prompt has. The environment is almost empty. (Just comspec, pathext, and prompt are set.) I'll try and pick up the env from the java app, and pass that as the env for the exec'd command.
Yup, this was the problem. Turns out that I needed to modify my exec all to pass "null" for the environment, instead of "new String[0]". (yeah, it's been a while since I used exec, and I've been working with a lib that doesn't allow any null parameters - so I picked up a bad habit.)
0

The password configure will not be used by git so that's not why things are working at the command line. What's more likely is that you set up your SSH keys to allow you to access your server without a password. This works at the command line but probably not when run from Java exec due to the environment being different.

You could try debugging the environment, I'm not sure what you need to do on Windows. Alternatively you could try configuring core.askpass. From the git config man page:

    core.askpass
    Some commands (e.g. svn and http interfaces) that interactively ask for a
    password can be told to use an external program given via the value of this
    variable. Can be overridden by the GIT_ASKPASS environment variable. If not
    set, fall back to the value of the SSH_ASKPASS environment variable or,
    failing that, a simple password prompt. The external program shall be given a
    suitable prompt as command line argument and write the password on its
    STDOUT.

1 Comment

Note that this is with a local git directory, NOT using a remote git repository. No SSH involved.

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.