Skip to content

Commit

Permalink
Add DSTASK_BRANCH var; defaults to master
Browse files Browse the repository at this point in the history
  • Loading branch information
dontlaugh committed Sep 14, 2021
1 parent ed474ae commit efb2097
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/dstask/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func main() {
}

case dstask.CMD_SYNC:
if err := dstask.CommandSync(conf.Repo); err != nil {
if err := dstask.CommandSync(conf); err != nil {
dstask.ExitFail(err.Error())
}

Expand Down
4 changes: 2 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ func CommandStop(conf Config, ctx, query Query) error {
}

// CommandSync pushes and pulls task database changes from the remote repository.
func CommandSync(repoPath string) error {
func CommandSync(conf Config) error {
// TODO(dontlaugh) return error
Sync(repoPath)
Sync(conf.Repo, conf.Branch)
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
// Config models the dstask application's required configuration. All paths
// are absolute.
type Config struct {
// Branch to use when pushing and pulling to git remote
Branch string
// Path to the git repository
Repo string
// Path to the dstask local state file. State will differ between machines
Expand All @@ -23,6 +25,7 @@ func NewConfig() Config {

var conf Config

conf.Branch = getEnv("DSTASK_BRANCH", "master")
conf.CtxFromEnvVar = getEnv("DSTASK_CONTEXT", "")
conf.Repo = getEnv("DSTASK_GIT_REPO", os.ExpandEnv("$HOME/.dstask"))
conf.StateFile = path.Join(conf.Repo, ".git", "dstask", "state.bin")
Expand Down
6 changes: 3 additions & 3 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func EnsureRepoExists(repoPath string) {

// Sync performs a git pull, and then a git push. If any conflicts are encountered,
// the user will need to resolve them.
func Sync(repoPath string) {
MustRunGitCmd(repoPath, "pull", "--no-rebase", "--no-edit", "--commit", "origin")
MustRunGitCmd(repoPath, "push", "origin")
func Sync(repoPath, branch string) {
MustRunGitCmd(repoPath, "pull", "--no-rebase", "--no-edit", "--commit", "origin", branch)
MustRunGitCmd(repoPath, "push", "origin", branch)
}

0 comments on commit efb2097

Please sign in to comment.