From 7fad1c2b4382df73c0859ba0b1f9ce65526e0118 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Fri, 13 Aug 2021 13:40:22 -0400 Subject: [PATCH] remove -t argument from `git remote add` command. fix #5 --- config.example.yaml | 7 +++---- git/clone.go | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index b4a3c3b..04b8dd2 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -35,10 +35,9 @@ git: pull_method: http # Must be set to either "init", or "clone". - # If set to "init", the local clone will be initialized with `git init` and set to track the default branch. (fastest) - # If set to "clone", the local clone will be initialized with `git clone`. (slowest) - # NOTE: If set to "init", the local clone will appear empty. Running `git pull` will download the files from the git server. - # It's highly recommended to leave this setting on "init". + # If set to "init", the local copy will be initialized with `git init` and the remote is configured manually. The git server is nerver queried. (fast) + # If set to "clone", the local copy will be initialized with `git clone`. (slow) + # NOTE: If set to "init", the local clone will appear empty. Running `git pull master` will download the files from the git server. on_clone: init # If set to true, the local clone will automatically run `git pull` in the local clone if it's on the default branch and the worktree is clean. diff --git a/git/clone.go b/git/clone.go index 19fc3a7..e4b90c5 100644 --- a/git/clone.go +++ b/git/clone.go @@ -49,7 +49,7 @@ func (c *gitClient) clone(gcp *gitCloneParam) error { _, err = utils.ExecProcessInDir( gcp.dst, // workdir "git", "remote", "add", - "-t", gcp.defaultBranch, + "-m", gcp.defaultBranch, "--", c.RemoteName, // name gcp.url, // url @@ -57,6 +57,30 @@ func (c *gitClient) clone(gcp *gitCloneParam) error { if err != nil { return fmt.Errorf("failed to setup remote %v in git repo %v: %v", gcp.url, gcp.dst, err) } + + // Configure the default branch + _, err = utils.ExecProcessInDir( + gcp.dst, // workdir + "git", "config", "--local", + "--", + fmt.Sprintf("branch.%s.remote", gcp.defaultBranch), // key + c.RemoteName, // value + + ) + if err != nil { + return fmt.Errorf("failed to setup default branch remote in git repo %v: %v", gcp.dst, err) + } + _, err = utils.ExecProcessInDir( + gcp.dst, // workdir + "git", "config", "--local", + "--", + fmt.Sprintf("branch.%s.merge", gcp.defaultBranch), // key + fmt.Sprintf("refs/heads/%s", gcp.defaultBranch), // value + + ) + if err != nil { + return fmt.Errorf("failed to setup default branch merge in git repo %v: %v", gcp.dst, err) + } } else { // Clone the repo _, err := utils.ExecProcess(