Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a default remote #62

Closed
wants to merge 3 commits into from
Closed

Allow setting a default remote #62

wants to merge 3 commits into from

Conversation

adamslc
Copy link
Collaborator

@adamslc adamslc commented Oct 5, 2018

Adds some code to read and write gitconfig files, and uses it to enable default remotes.

This is based off code at go-gitconfig. I would have just used that code, but the project seems abandoned, and it is licensed as MIT.

Closes #11.

Based on MIT licensed coded at github.com/tcnksm/go-gitconfig
Also allows push command to set default remote.
The commit doesn't add the ability to set the default remote in termui.
I'm not sure that functionality is necessary, but it would be easy to add.
return err
}

fmt.Println("Default remote: ", str)

Choose a reason for hiding this comment

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

unreachable code

func runPush(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return errors.New("Only pushing to one remote at a time is supported")
}

remote := "origin"
if len(args) == 0 && defaultRemote {
str, err := git.GetConfig("gitbug.defaultremote")

Choose a reason for hiding this comment

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

this value of str is never used

@MichaelMure
Copy link
Owner

Damn, you are on fire 🎉 🎉 🎉

Instead of importing part of go-gitconfig, you can use the interface function RepoCommon.ReadConfigs(). It's implemented by both the low level GitRepo and RepoCache. This function will read all values matching a prefix. If that's inconvenient, you can add a new function to read a single entry.

pushCmd.Flags().SortFlags = false

pushCmd.Flags().BoolVarP(&defaultRemote, "default", "d", false,
"If a remote is provided, set the default remote for future pushes. Otherwise list the default remote if one exists.")
Copy link
Owner

Choose a reason for hiding this comment

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

In term of UX that's not good. The push command should not have a lasting effect on the config. All the git-bug config manipulation should be centralized in a new config command. I guess it would be better to open an issue, see what it should cover and design this new command.

Copy link
Collaborator Author

@adamslc adamslc Oct 5, 2018

Choose a reason for hiding this comment

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

Hmm, I see the argument, but a standard git push can already have a lasting effect on the repo config with e.g. --set-upstream. Even if there is a config command, it still seems like you should be able to both push to a remote and set that remote as the default at the same time.

@MichaelMure
Copy link
Owner

Sorry to rain on the parade :-\

Maybe before starting a new feature, contact me so I can give you the useful pointers and we can design the thing together. There is either the gitter lobby, a github issue or my mail (in my github profile). As I'm starting a new job on Monday I will be a bit less responsive though.

Btw, if you are looking for a new target, it would be awesome to have a proper window in the termui to edit the search query, with widget and selectors (a bit like the toolbar in https://github.com/MichaelMure/git-bug/issues).

Again, sorry to be annoying :-|

@adamslc
Copy link
Collaborator Author

adamslc commented Oct 5, 2018

No worries. This didn't take very long at all to knock up, so I'm not that attached to it.

@MichaelMure
Copy link
Owner

This is still a valid feature but the code for commands has moved so much that it would need to be reimplemented. At the same time, reading the git config is now integral part of Repo so it would be way easier to do.

Sorry :-\

@mcepl
Copy link
Contributor

mcepl commented Jan 13, 2024

@adamslc Is there any hope that you would revive this PR? I usually reserve origin for the original repo I branch from, and so it is usually the one repository I have no access to.

lbedford pushed a commit to daedaleanai/git-ticket that referenced this pull request Jul 2, 2024
…lMure#62) from ja/FixReferenceUpdatedConcurrently into master

Reviewed-on: https://gitea.daedalean.ai/daedalean-github/git-ticket/pulls/62
Reviewed-by: Johannes Frohnhofen <jf@daedalean.ai>
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.

feat: configuration for the default remote
4 participants