dstask
dstask copied to clipboard
Make git branch name configurable
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 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.
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 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.
Is there a smarter way, where you can query the default upstream branch via git?
@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..? 🤔
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).
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
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.
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.
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.
Understood and thank you for the update.