Get default fetch remote from configuration
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_repowhich reads git configuration related to remote repositories. It first readsbranch.<name>.remote. This is according to the docs.
I followed the checklist:
- [x] I added unittests
- [x] I ran
make checkwithout 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
originto 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-fetchsays: “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.<>.remoteis set
@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.
Awesome!! I am going to review it tomorrow !
does this fix #1093 now?
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> ?
@cruessler
does this fix https://github.com/extrawurst/gitui/issues/1093 now?
if so, lets mark that in the changelog
@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
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. 😄