Skip to content

Commit

Permalink
Checkout to branch on init, if any provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriiklymiuk committed Dec 7, 2022
1 parent d65c89d commit d02b25e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ var serviceItems = []CorgiComposeItems{
itemType: "string",
description: "Git url to target repo. By default nothing is cloned.",
},
{
item: "branch",
example: "some/feature/branch",
itemType: "string",
description: "Branch to use for git checkout. By default default branch for repo is used.",
},
{
item: "environment",
example: "- YOUR_ENV=dev\n\t- YOUR__ANTOHER_ENV=abcdef",
Expand Down
34 changes: 28 additions & 6 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
"text/template"

Expand Down Expand Up @@ -141,14 +140,37 @@ func CloneServices(services []utils.Service) {
continue
}

cmd := exec.Command("git", "clone", service.CloneFrom)
cmd.Dir = pathWithoutLastFolder
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
err = utils.RunServiceCmd(
service.ServiceName,
fmt.Sprintf("git clone %s", service.CloneFrom),
pathWithoutLastFolder,
)
if err != nil {
fmt.Printf(`output error: %s, in path %s with git clone %s
`, err, pathWithoutLastFolder, service.CloneFrom)
continue
}
if service.Branch != "" {
err = utils.RunServiceCmd(
service.ServiceName,
fmt.Sprintf("git checkout %s", service.Branch),
service.Path,
)
if err != nil {
fmt.Printf(`output error: %s, in path %s with git checkout %s
`, err, service.Path, service.Branch)
continue
}
err = utils.RunServiceCmd(
service.ServiceName,
"git pull",
service.Path,
)
if err != nil {
fmt.Printf(`output error: %s, in path %s with git pull %s
`, err, service.Path, service.Branch)
continue
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions resources/readme/corgi_compose_items.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Corgi compose `service` can contain the following items (properties):
| Item | Example | itemType | Description
| ------------| :------------- | - | --
| cloneFrom | `[email protected]:Andriiklymiuk/corgi.git` | `string` | Git url to target repo. By default nothing is cloned.
| branch | `some/feature/branch` | `string` | Branch to use for git checkout. By default default branch for repo is used.
| environment | - YOUR_ENV=dev<br>- YOUR__ANTOHER_ENV=abcdef | `[]string` | List of environment variables to copy and put into your env file.<br>By default no environments are added.
| envPath | ./path/to/.env | `string` | Path to .env file in target repo. By default .env file is used
| ignoreEnv | false | `string` | Should service ignore env and don't change env file or not. By default is false (env is not ignored)
Expand Down
2 changes: 2 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Service struct {
IgnoreEnv bool `yaml:"ignore_env"`
ManualRun bool `yaml:"manualRun"`
CloneFrom string `yaml:"cloneFrom"`
Branch string `yaml:"branch"`
Environment []string `yaml:"environment"`
EnvPath string `yaml:"envPath"`
CopyEnvFromFilePath string `yaml:"copyEnvFromFilePath"`
Expand Down Expand Up @@ -176,6 +177,7 @@ func GetCorgiServices(cobra *cobra.Command) (*CorgiCompose, error) {
IgnoreEnv: service.IgnoreEnv,
ManualRun: service.ManualRun,
CloneFrom: service.CloneFrom,
Branch: service.Branch,
DependsOnServices: service.DependsOnServices,
DependsOnDb: service.DependsOnDb,
Environment: service.Environment,
Expand Down

0 comments on commit d02b25e

Please sign in to comment.