gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Get default fetch remote from configuration

Open cruessler opened this issue 1 year ago • 7 comments

This PR is in response to #1093. It changes how GitUI gets the remote to fetch from.

This is a follow-up PR to #2156 which added similar behaviour for pushing.

It changes the following:

  • It adds get_default_remote_for_fetch_in_repo which reads git configuration related to remote repositories. It first reads branch.<name>.remote. This is according to the docs.

I followed the checklist:

  • [x] I added unittests
  • [x] I ran make check without errors
  • [x] I tested the overall application
  • [x] I added an appropriate item to the changelog

Test fetch/pull behavior in status tab:

  • [x] no upstream branch configured If no upstream branch is configured, you still can’t fetch from a remote if you have renamed origin to something else, e. g. non-origin. I think this is the right thing to do for the time being. As far as I’m aware, we want to provide a UI allowing users to choose a branch to fetch from in the future. man git-fetch says: “When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch.”
  • [x] upstream branch configured, branch.<>.remote is set

cruessler avatar Apr 24 '24 19:04 cruessler

@extrawurst This PR is now ready for review. It is hopefully a small step towards making the error message git: inconclusive remotes disappear. :smile:

Once it is merged, GitUI should respect configured remote branches for fetching and pushing. We could then start implementing a fallback for when no remote branch is configured. I’m also thinking about creating a couple good first issues in order to deduplicate/clean up some of the new code.

cruessler avatar May 01 '24 10:05 cruessler

Awesome!! I am going to review it tomorrow !

extrawurst avatar May 01 '24 16:05 extrawurst

does this fix #1093 now?

extrawurst avatar May 02 '24 15:05 extrawurst

lgtm. just one thing:

I’m also thinking about creating a couple good first issues in order to deduplicate/clean up some of the new code.

can you mark the places with //TODO: <description> ?

extrawurst avatar May 02 '24 15:05 extrawurst

@cruessler

does this fix https://github.com/extrawurst/gitui/issues/1093 now?

if so, lets mark that in the changelog

extrawurst avatar May 05 '24 19:05 extrawurst

@cruessler

does this fix https://github.com/extrawurst/gitui/issues/1093 now?

if so, lets mark that in the changelog

I’ll have a look tomorrow on the train!

cruessler avatar May 05 '24 20:05 cruessler

@cruessler

does this fix #1093 now?

if so, lets mark that in the changelog

As far as I can tell, this fixes #1093. I’ve updated the changelog entry. This is how I prepared the repository before I tested the branch:

❯ git remote rename origin non-origin

❯ git remote
non-origin
upstream

❯ git push non-origin
[…]
 * [new branch]      test-remotes -> test-remotes
branch 'test-remotes' set up to track 'non-origin/test-remotes'.

❯ git remote set-url non-origin [email protected]:cruessler/gitui.git

❯ git config --list | grep non-origin
[email protected]:cruessler/gitui.git
remote.non-origin.fetch=+refs/heads/*:refs/remotes/non-origin/*
branch.test-remotes.remote=non-origin

I was able to successfully pull in this setup. Since git automatically sets up branch.<>.remote, the only reason this does not fix the issue would be additional local configuration. Or something else I don’t know yet. 😄

cruessler avatar May 06 '24 07:05 cruessler