gitui icon indicating copy to clipboard operation
gitui copied to clipboard

gitui doesn't honor pushInsteadOf settings

Open mkhl opened this issue 4 years ago • 9 comments
trafficstars

Describe the bug Pushing to a remote that has a https url ignores an associated pushInsteadOf ssh url and prompts for a username.

To Reproduce Steps to reproduce the behavior:

  1. Clone a repository via https, e.g. git clone https://github.com/extrawurst/gitui.git
  2. Add a pushInsteadOf ssh url, e.e.g by adding this to your git config:
    [url "[email protected]:extrawurst/"]
        pushInsteadOf = "https://github.com/extrawurst/"
    
  3. Commit anything
  4. See gitui prompt for a username

Expected behavior gitui uses the configured ssh url and pushes successfully instead of prompting for credentials

Context (please complete the following information):

  • OS/Distro + Version: Fedora 34
  • GitUI Version: gitui 0.16.2 (installed with dnf)
  • Rust version: rustc 1.55.0 (Fedora 1.55.0-1.fc34)

Additional context Documentation for pushInsteadOf

mkhl avatar Oct 20 '21 21:10 mkhl

Hm weird this should actually be working correctly since https://github.com/libgit2/libgit2/pull/3048

extrawurst avatar Oct 20 '21 21:10 extrawurst

Huh, agreed, that looks like it should prevent this. Is there a way to get debug output about what gitui is pushing to, or what configuration it read?

FWIW my configuration is in ~/.config/git/config which has occasionally caused problems but I'd expect libgit2 handles that case.

mkhl avatar Oct 20 '21 21:10 mkhl

maybe we can learn anything from delta here: https://github.com/dandavison/delta/pull/694/files

extrawurst avatar Oct 27 '21 07:10 extrawurst

i believe this is a bug in libgit2, or at least the version currently used in git2-rs. this line is where the pushInsteadOf setting is applied, but is seems that code is only reached when the remote has an explicit pushurl setting. the correct behavior would be to apply pushinsteadof to the url instead if there is no pushurl.

this also seems consistent with what i found in gitui, that the used remote has a url but not a pushurl

mkhl avatar Oct 27 '21 12:10 mkhl

a related problem is that need_username_password should check the pushurl if there is one, because only that would have the replacement applied

mkhl avatar Oct 27 '21 12:10 mkhl

i believe this is a bug in libgit2, or at least the version currently used in git2-rs. this line is where the pushInsteadOf setting is applied, but is seems that code is only reached when the remote has an explicit pushurl setting. the correct behavior would be to apply pushinsteadof to the url instead if there is no pushurl.

libgit2/libgit2#6099

mkhl avatar Oct 27 '21 13:10 mkhl

libgit2/libgit2#6101 would fix this

mkhl avatar Oct 28 '21 14:10 mkhl

https://github.com/libgit2/libgit2/pull/6101 Is merged, now we need to get it into git2-rs upstream

extrawurst avatar Jan 01 '22 14:01 extrawurst

libgit2 release 1.4.0 released this now: https://github.com/libgit2/libgit2/releases/tag/v1.4.0

extrawurst avatar Feb 13 '22 18:02 extrawurst

This issue has been automatically marked as stale because it has not had any activity half a year. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 13 '22 02:08 stale[bot]

this is fixed in v0.21.0 :tada:

mkhl avatar Aug 22 '22 13:08 mkhl