doInitialCommit runs the git commands that initialize and do the first commit to a repository.
(ownerName string, repositoryName string)
| 171 | |
| 172 | // doInitialCommit runs the git commands that initialize and do the first commit to a repository. |
| 173 | func doInitialCommit(ownerName string, repositoryName string) error { |
| 174 | remoteOrigin := fmt.Sprintf("git@github.com:%s/%s.git", ownerName, repositoryName) |
| 175 | |
| 176 | initDefaultBranch := getInitDefaultBranch() |
| 177 | |
| 178 | commands := []initialCommands{ |
| 179 | { |
| 180 | description: "git init", |
| 181 | command: "git", |
| 182 | args: []string{"init"}, |
| 183 | }, |
| 184 | { |
| 185 | description: "git add .", |
| 186 | command: "git", |
| 187 | args: []string{"add", "."}, |
| 188 | }, |
| 189 | { |
| 190 | description: "git commit -m \"initial commit by zero\"", |
| 191 | command: "git", |
| 192 | args: []string{"commit", "-m", "initial commit by zero"}, |
| 193 | }, |
| 194 | { |
| 195 | description: fmt.Sprintf("git remote add origin %s", remoteOrigin), |
| 196 | command: "git", |
| 197 | args: []string{"remote", "add", "origin", remoteOrigin}, |
| 198 | }, |
| 199 | { |
| 200 | description: fmt.Sprintf("git push -u origin %s", initDefaultBranch), |
| 201 | command: "git", |
| 202 | args: []string{"push", "-u", "origin", initDefaultBranch}, |
| 203 | }, |
| 204 | } |
| 205 | |
| 206 | for _, command := range commands { |
| 207 | // TODO: Debug-level logging? |
| 208 | // fmt.Printf(">> %s\n", command.description) |
| 209 | |
| 210 | cmd := exec.Command(command.command, command.args...) |
| 211 | cmd.Dir = "./" + repositoryName |
| 212 | flog.Debugf("Running (%s) command in %s, %#v", command.command, cmd.Dir, command.args) |
| 213 | _, err := cmd.CombinedOutput() |
| 214 | if err != nil { |
| 215 | fmt.Printf("ERROR: failed to run %s: %s\n", command.description, err.Error()) |
| 216 | // this is a partial failure. some commands may have exec'ed successfully. |
| 217 | break |
| 218 | } //else { |
| 219 | // TODO: Debug-level logging? |
| 220 | // response := string(out) |
| 221 | // if len(response) > 0 { |
| 222 | // fmt.Println(response) |
| 223 | // } |
| 224 | // } |
| 225 | } |
| 226 | |
| 227 | return nil |
| 228 | } |
no test coverage detected