dstask icon indicating copy to clipboard operation
dstask copied to clipboard

Make git branch name configurable

Open kevindkeogh opened this issue 4 years ago • 12 comments
trafficstars

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?

https://github.com/naggie/dstask/blob/05f55e1c0c50dc7937ddf9e778be625bbd551609/git.go#L95

Thank you!

kevindkeogh avatar Jan 23 '21 02:01 kevindkeogh

@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.

dontlaugh avatar Feb 03 '21 16:02 dontlaugh

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

kevindkeogh avatar Feb 03 '21 17:02 kevindkeogh

@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.

dontlaugh avatar Sep 14 '21 01:09 dontlaugh

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

naggie avatar May 09 '23 14:05 naggie

@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..? 🤔

adamsoderstrom avatar May 10 '23 06:05 adamsoderstrom

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).

dontlaugh avatar May 11 '23 21:05 dontlaugh

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 avatar May 12 '23 08:05 naggie

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.

naggie avatar Jun 08 '23 21:06 naggie

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.

rharmonson avatar Aug 29 '23 19:08 rharmonson

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.

naggie avatar Sep 10 '23 17:09 naggie

Understood and thank you for the update.

rharmonson avatar Sep 10 '23 18:09 rharmonson