Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@eekhof
Copy link
Contributor

@eekhof eekhof commented Mar 2, 2025

This fixes #322 , so that if no remote to push to is set, the default option set by

[remote]
	pushDefault = origin

Is used instead.

@altsem
Copy link
Owner

altsem commented Mar 3, 2025

I'm a bit confused, so had a look at the man git config.

       remote.pushDefault
           The remote to push to by default. Overrides branch.<name>.remote for all branches, and is
           overridden by branch.<name>.pushRemote for specific branches.

What does Overrides branch.<name>.remote for all branches actually mean? 🤔

       branch.<name>.remote
           When on branch <name>, it tells git fetch and git push which remote to fetch from or push to.
           The remote to push to may be overridden with remote.pushDefault (for all branches). The
           remote to push to, for the current branch, may be further overridden by
           branch.<name>.pushRemote. If no remote is configured, or if you are not on any branch and
           there is more than one remote defined in the repository, it defaults to origin for fetching
           and remote.pushDefault for pushing. Additionally, . (a period) is the current local
           repository (a dot-repository), see branch.<name>.merge's final note below.

       branch.<name>.pushRemote
           When on branch <name>, it overrides branch.<name>.remote for pushing. It also overrides
           remote.pushDefault for pushing from branch <name>. When you pull from one place (e.g. your
           upstream) and push to another place (e.g. your own publishing repository), you would want to
           set remote.pushDefault to specify the remote to push to for all branches, and use this option
           to override it for a specific branch.

It feels like a can of worm has opened up since the introduction of the two remotes (upstream/pushRemote). 😅

update:

Nevermind. I found this in Magit. Let's stick with how you've prioritized them (branch.<name>.remote over remote.pushDefault)

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests are failing (cargo test).
It's also possible to add a test like (in src/tests/push.rs):

#[test]
fn push_doesnt_prompt_for_remote_when_default_set() {
    let ctx = TestContext::setup_clone();
    run(ctx.dir.path(), &["git", "checkout", "-b", "new-branch"]);
    commit(ctx.dir.path(), "new-file", "");
    run(
        ctx.dir.path(),
        &["git", "config", "remote.pushDefault", "origin"],
    );

    snapshot!(ctx, "Pp<enter>");
}

if config.get_string(&push_default_cfg).is_ok() {
Ok(push_default_cfg)
} else {
Err("Neither pushRemote nor push.default is configured".into())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err("Neither pushRemote nor push.default is configured".into())
Err("Neither branch.<name>.pushRemote nor remote.pushDefault is configured".into())

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push.default is something else (Defaults to "simple" etc.)

@altsem
Copy link
Owner

altsem commented Apr 17, 2025

This was duplicated in #347.
It's merged now, so I'll close this.

@eekhof
Copy link
Contributor Author

eekhof commented May 5, 2025

Thanks for this! And sorry for going silent, I thought I would have more free time when I initially submitted the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pushing does not respect pushDefault git option [correction]

2 participants