martinvonz / jj

A Git-compatible VCS that is both simple and powerful
https://martinvonz.github.io/jj/
Apache License 2.0
8.08k stars 265 forks source link

`jj` can't set up new git `credential.helper` entries #4101

Open kfkonrad opened 1 month ago

kfkonrad commented 1 month ago

Description

I tried using jj with a credential.helper set in my global gitconfig as per the documentation. I ran jj git fetch and was asked for username and password.

Then I tried doing a git fetch for the same host and entered my credentials. After that they were stored in the credential store and jj was able to retrieve them. They weren't in there before then because I normally use ssh or the VS Code GIT_ASKPASS. (Supporting GIT_ASKPASS might be worth discussing as well, but that's out of scope for this issue.)

Somewhat relatedly I found the documentation for credential.helper confusing (in git-compatibility). I'd suggest wording it more clearly that this is read from the default gitconfig as opposed to jj's config like almost every other setting. Also on the same page the first listed supported feature mentions which git settings will be taken into account when using jj. Adding credential.helper to that list would help clear up the wording

Steps to Reproduce the Problem

  1. Be in a jj repo (a colocated is easiest, but any backed by git will do)
  2. Run git config --global credential.helper osxkeychain (using your OS's helper)
  3. Make sure there's no entry for the git host configured
  4. Run jj git fetch

Expected Behavior

jj should either:

inform the user that no entry was found for the given host and instruct them to add one using git or the credential helper itself

OR

add the entry using the helper and inform the user that it is doing so.

Actual Behavior

jj silently falls back to asking for username/password interactively and does not store the credentials using the helper.

Specifications

Let me know if I can be of help in resolving the issue (such as submitting an update to the docs as a PR)

alec-atbay commented 1 month ago

What is the url remote for the git repo? Sometimes git handles things differently depending on the protocol. For example, ssh remotes never respect the credential helper value, even in git.

Does plan git fetch respect the config variable and its just jj that fails?

kfkonrad commented 1 month ago

The URL is https://gitlab.com/foo/bar.git

jj only fails (i.e. falls back to asking for credentials interactively) if none are set for the given host in the credential helper. git fetch also asks for credentials interactively if none are set for the given host but it stores them using the credential helper afterwards

Since jj doesn't store the credentials if none are found it asks for them every time. Calling git fetch once fixes that (because git fetch stores the credentials which jj will then read and use as expected) but I'd expect jj to not be dependent on running plain git commands