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

Make git branch name configurable #116

Open
kevindkeogh opened this issue Jan 23, 2021 · 12 comments
Open

Make git branch name configurable #116

kevindkeogh opened this issue Jan 23, 2021 · 12 comments

Comments

@kevindkeogh
Copy link

Hi all,

Great tool. I typically use main as my main git branch name, and noticed that master is hardcoded in the dstask sync command. Was wondering if it was possible to make the branch name configurable?

dstask/git.go

Line 95 in 05f55e1

MustRunGitCmd(repoPath, "pull", "--no-rebase", "--no-edit", "--commit", "origin", "master")

Thank you!

dontlaugh added a commit to gloriousfutureio/dstask that referenced this issue Jan 26, 2021
It is possible to specify an alternative default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

Refs naggie#116
@dontlaugh
Copy link
Contributor

@kevindkeogh If you are willing to build a custom branch, see my fork in #118 and see if it fixes your issues.

I am having a heck of a time getting the tests to pass, though. Some kind of Go modules issue.

@kevindkeogh
Copy link
Author

This worked perfectly for me, thank you!

If its any help, I ran

git clone https://github.com/gloriousfutureio/dstask.git
cd dstask
git checkout rely_on_default_branch 
go mod vendor
make
./dist/dstask sync
$ go version
go version go1.15.7 linux/amd64

dontlaugh added a commit to gloriousfutureio/dstask that referenced this issue Mar 20, 2021
It is possible to specify an alternative default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

Refs naggie#116
dontlaugh added a commit to gloriousfutureio/dstask that referenced this issue Mar 20, 2021
It is possible to specify an alternative default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

Refs naggie#116
dontlaugh added a commit to gloriousfutureio/dstask that referenced this issue Mar 31, 2021
It is possible to specify an alternative default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

Refs naggie#116
dontlaugh added a commit to gloriousfutureio/dstask that referenced this issue Apr 8, 2021
It is possible to specify an alternative default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

Refs naggie#116
dontlaugh added a commit to dontlaugh/dstask that referenced this issue Jul 12, 2021
We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

In git 2.32, it's possible to specify the default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

Refs naggie#116
dontlaugh added a commit to dontlaugh/dstask that referenced this issue Jul 12, 2021
We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

In git 2.32, it's possible to specify the default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

Refs naggie#116
dontlaugh added a commit to dontlaugh/dstask that referenced this issue Jul 12, 2021
We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

In git 2.32, it's possible to specify the default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

Refs naggie#116
dontlaugh added a commit to dontlaugh/dstask that referenced this issue Jul 12, 2021
We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

In git 2.32, it's possible to specify the default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

Refs naggie#116
dontlaugh added a commit to dontlaugh/dstask that referenced this issue Sep 14, 2021
We should be able to rely on pushing and pulling from the default
branch without explicitly setting "master", or anything else. dstask
will simply push and pull from the remote named "origin" using whatever
default tracking branch is set.

In git 2.32, it's possible to specify the default initial branch for git
repositories. This is globally configurable with **init.defaultBranch**.
See `man git-init` for details.

Refs naggie#116
@dontlaugh
Copy link
Contributor

@kevindkeogh I spoke to naggie and we're taking a different approach.

We will ask users to set a DSTASK_BRANCH environment variable to change the git branch. The default will be master, for backwards compatibility.

This is just a heads up. See the associated PR if you're interested.

@naggie
Copy link
Owner

naggie commented May 9, 2023

Is there a smarter way, where you can query the default upstream branch via git?

@adamsoderstrom
Copy link

@naggie

Hm... maybe! According to Git's "Remote Branches" documentation, it appears as you could retrieve the remote branches via git branch -vv.

If one would change branch, then one would probably expect the tasks to be pushed on that branch..? 🤔

@dontlaugh
Copy link
Contributor

It has been a while since I've thought about this issue, specifically. However, I've spent quite a few hours writing automation around git for various day jobs, and my inuition is that there isn't a robust way to do this without adding extra config. Git is fundamentally distributed, and I think there will always be some failure modes if we are to rely on git config itself to carry this little bit of state around (the branch name).

@naggie
Copy link
Owner

naggie commented May 12, 2023

I suppose we could list origin remote branches as @adamsoderstrom says and if the list contains main but not master pick main -- and nice versa.

Or, require an upstream tracking branch to be configured for the current branch, and push/pull from that implicitly

@naggie
Copy link
Owner

naggie commented Jun 8, 2023

image

This logic works for a command I wrote in bash. I suggest we use it here -- I don't think there are any use cases for regular use of a branch that isn't master or main.

@rharmonson
Copy link

rharmonson commented Aug 29, 2023

What is the state of this?

I attempted to assign 'DSTASK_BRANCH=main' with bash without success with v0.26. Gave up and create a new branch, master, set it as default, protected it, and deleted the main branch.

I am using gitlab.com which moved from "master" to "main" due to the former being offensive, apparently. Silliness!

Everything worked after my changes.

@naggie
Copy link
Owner

naggie commented Sep 10, 2023

DSTASK_BRANCH is not an environment variable you can use, just an idea inside this issue.

I think there's a way we can automatically detect the branch as detailed above. It's just not implemented yet.

@rharmonson
Copy link

Understood and thank you for the update.

@qTipTip
Copy link

qTipTip commented Oct 10, 2024

Could we use init.defaultBranch here?

In that case, we can fetch the default branch name by git config --get init.defaultBranch. If it is not set, it will default to master.

Or, do something like they do in the fish git plugin:

https://github.com/jhillyerd/plugin-git/blob/master/functions/__git.default_branch.fish

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 a pull request may close this issue.

6 participants