Skip to content

Commit

Permalink
allow selecting git client
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomanski committed Apr 24, 2017
1 parent c480203 commit cc622ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
20 changes: 16 additions & 4 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,27 @@ type BuildsRepo struct {
client RepoClient
}

func PrepareRepo() (*BuildsRepo, error) {
func PrepareRepo(gitClient string) (*BuildsRepo, error) {
dir, err := ioutil.TempDir("", "tagger")
if err != nil {
return nil, err
}

c, err := newFromLibgit(dir)
if err != nil {
return nil, err
var c RepoClient

switch gitClient {
case "libgit":
c, err = newFromLibgit(dir)
if err != nil {
return nil, err
}
case "command":
c, err = newFromCommand(dir)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("Unknown git client '%s'", gitClient)
}

return &BuildsRepo{directory: dir, client: c}, nil
Expand Down
4 changes: 2 additions & 2 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestPrepareRepo(t *testing.T) {
repo, err := PrepareRepo()
repo, err := PrepareRepo("libgit")
assert.Nil(t, err)
defer repo.Close()

Expand All @@ -30,7 +30,7 @@ func TestPrepareRepo(t *testing.T) {
}

func TestAddAndCommit(t *testing.T) {
repo, err := PrepareRepo()
repo, err := PrepareRepo("libgit")
assert.Nil(t, err)
defer repo.Close()

Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ type taggerOptionsArgs struct {
type taggerOptions struct {
Args taggerOptionsArgs `positional-args:"true" required:"true"`

Commit bool `short:"c" long:"commit" description:"Commit the changes. Will make a dry run without this flag."`
Build int32 `short:"b" long:"build" required:"false" default:"0" description:"Specify the build number to be placed inside the JSON."`
URL string `short:"u" long:"url" description:"Release notes URL"`
Codename string `short:"n" long:"codename" description:"Release codename"`
Commit bool `short:"c" long:"commit" description:"Commit the changes. Will make a dry run without this flag."`
Build int32 `short:"b" long:"build" required:"false" default:"0" description:"Specify the build number to be placed inside the JSON."`
URL string `short:"u" long:"url" description:"Release notes URL"`
Codename string `short:"n" long:"codename" description:"Release codename"`
GitClient string `long:"git-client" default:"libgit" description:"Git client. Either 'libgit' or 'command'"`
}

func retaggingStep(images map[string]string, opts *taggerOptions, tagTimestamp string) {
Expand Down Expand Up @@ -155,7 +156,7 @@ func main() {
fmt.Printf("Tag timestamp: %s\n", tagTimestamp)
fmt.Printf("ISO timestamp: %s\n", isoTimestamp)

repo, err := git.PrepareRepo()
repo, err := git.PrepareRepo(opts.GitClient)
if err != nil {
log.Fatalf("Failed to clone the builds repo: %s", err.Error())
}
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var testOldJSON = `[
// TestRenamedImages tests whether the image list
// contains the same images with altered tags
func TestRenamedImages(t *testing.T) {
repo, err := git.PrepareRepo()
repo, err := git.PrepareRepo("libgit")
assert.Nil(t, err)
defer repo.Close()

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestRenamedImages(t *testing.T) {

// TestRenamedImages2 tests whether the Codename and URL have been updated
func TestRenamedImages2(t *testing.T) {
repo, err := git.PrepareRepo()
repo, err := git.PrepareRepo("libgit")
assert.Nil(t, err)
defer repo.Close()

Expand Down Expand Up @@ -200,7 +200,7 @@ func TestRenamedImages2(t *testing.T) {
// TestRenamedImages3 tests whether the image list
// contains the same images with unchanged tags
func TestRenamedImages3(t *testing.T) {
repo, err := git.PrepareRepo()
repo, err := git.PrepareRepo("libgit")
assert.Nil(t, err)
defer repo.Close()

Expand Down Expand Up @@ -271,7 +271,7 @@ func TestRenamedImages3(t *testing.T) {
}

func TestRenamedImagesBuildIncrement(t *testing.T) {
repo, err := git.PrepareRepo()
repo, err := git.PrepareRepo("libgit")
assert.Nil(t, err)
defer repo.Close()

Expand Down

0 comments on commit cc622ba

Please sign in to comment.