-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: git push command use branch name from init.defaultBranch…
… in git config
- Loading branch information
Showing
1 changed file
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,9 +154,30 @@ type initialCommands struct { | |
args []string | ||
} | ||
|
||
// getInitDefaultBranch return init.defaultBranch value in git config. | ||
// If init.defaultBranch isn't set, getInitDefaultBranch return 'master'. | ||
func getInitDefaultBranch() string { | ||
var initDefaultBranch string | ||
|
||
cmd := exec.Command("git", "config", "--get", "init.defaultBranch") | ||
|
||
output, err := cmd.CombinedOutput() | ||
|
||
if err != nil { | ||
initDefaultBranch = "master" | ||
} else { | ||
initDefaultBranch = string(output) | ||
} | ||
|
||
return initDefaultBranch | ||
} | ||
|
||
// doInitialCommit runs the git commands that initialize and do the first commit to a repository. | ||
func doInitialCommit(ownerName string, repositoryName string) error { | ||
remoteOrigin := fmt.Sprintf("[email protected]:%s/%s.git", ownerName, repositoryName) | ||
|
||
initDefaultBranch := getInitDefaultBranch() | ||
|
||
commands := []initialCommands{ | ||
{ | ||
description: "git init", | ||
|
@@ -179,9 +200,9 @@ func doInitialCommit(ownerName string, repositoryName string) error { | |
args: []string{"remote", "add", "origin", remoteOrigin}, | ||
}, | ||
{ | ||
description: "git push -u origin master", | ||
description: fmt.Sprintf("git push -u origin %s", initDefaultBranch), | ||
command: "git", | ||
args: []string{"push", "-u", "origin", "master"}, | ||
args: []string{"push", "-u", "origin", initDefaultBranch}, | ||
}, | ||
} | ||
|
||
|