diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-09-06 10:55:29 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-09-06 10:55:29 +0300 |
commit | cefa69b19273b861f5a830709441e132f866417b (patch) | |
tree | b2fbb59be2a98b9967171b41faa48ca23c71b386 | |
parent | 934d09b8fac8301d787ca5322aab90da75b7675d (diff) |
Use testhelper.CreateTag to have a Git ident
Locally I can't run some tests as Git would like to know the identity of
the user creating new objects. In my case these object creations get the
following message:
```
testhelper.go:184:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <zegerjan@callisto.localdomain>) not allowed
```
Now, this leverages system packages on the Git side to determine the
identname. In our case I think the best way to move forward is just to
use the `testhelper.CreateTag()`, which sets the ident for us.
-rw-r--r-- | internal/service/remote/update_remote_mirror_test.go | 17 | ||||
-rw-r--r-- | internal/testhelper/tag.go | 8 |
2 files changed, 18 insertions, 7 deletions
diff --git a/internal/service/remote/update_remote_mirror_test.go b/internal/service/remote/update_remote_mirror_test.go index de35d348c..b1a64389e 100644 --- a/internal/service/remote/update_remote_mirror_test.go +++ b/internal/service/remote/update_remote_mirror_test.go @@ -26,7 +26,10 @@ func TestSuccessfulUpdateRemoteMirrorRequest(t *testing.T) { remoteName := "remote_mirror_1" - testhelper.MustRunCommand(t, nil, "git", "-C", mirrorPath, "tag", "v0.0.1", "master") // I needed another tag for the tests + testhelper.CreateTag(t, mirrorPath, "v0.0.1", "master", nil) // I needed another tag for the tests + testhelper.CreateTag(t, testRepoPath, "new-tag", "60ecb67744cb56576c30214ff52294f8ce2def98", nil) + testhelper.CreateTag(t, testRepoPath, "v1.0.0", "0b4bc9a49b562e85de7cc9e834518ea6828729b9", &testhelper.CreateTagOpts{ + Message: "Overriding tag", Force: true}) setupCommands := [][]string{ // Preconditions @@ -39,8 +42,6 @@ func TestSuccessfulUpdateRemoteMirrorRequest(t *testing.T) { {"update-ref", "refs/heads/empty-branch", "0b4bc9a49b562e85de7cc9e834518ea6828729b9"}, // Update branch {"branch", "-D", "not-merged-branch"}, // Delete branch // Scoped to the project, so will be removed after - {"tag", "new-tag", "60ecb67744cb56576c30214ff52294f8ce2def98"}, // Add tag - {"tag", "-fam", "Overriding tag", "v1.0.0", "0b4bc9a49b562e85de7cc9e834518ea6828729b9"}, // Update tag {"tag", "-d", "v0.0.1"}, // Delete tag } @@ -116,11 +117,13 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) { {"update-ref", "refs/heads/some-branch", "0b4bc9a49b562e85de7cc9e834518ea6828729b9"}, // Update branch {"update-ref", "refs/heads/feature", "0b4bc9a49b562e85de7cc9e834518ea6828729b9"}, // Update branch // Scoped to the project, so will be removed after - {"branch", "-D", "not-merged-branch"}, // Delete branch - {"tag", "new-tag", "60ecb67744cb56576c30214ff52294f8ce2def98"}, // Add tag - {"tag", "-fam", "Overriding tag", "v1.0.0", "0b4bc9a49b562e85de7cc9e834518ea6828729b9"}, // Update tag + {"branch", "-D", "not-merged-branch"}, // Delete branch } + testhelper.CreateTag(t, testRepoPath, "new-tag", "60ecb67744cb56576c30214ff52294f8ce2def98", nil) // Add tag + testhelper.CreateTag(t, testRepoPath, "v1.0.0", "0b4bc9a49b562e85de7cc9e834518ea6828729b9", + &testhelper.CreateTagOpts{Message: "Overriding tag", Force: true}) // Update tag + for _, args := range setupCommands { gitArgs := []string{"-C", testRepoPath} gitArgs = append(gitArgs, args...) @@ -129,7 +132,7 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) { // Workaround for https://gitlab.com/gitlab-org/gitaly/issues/1439 // Create a tag on the remote to ensure it gets deleted later - testhelper.MustRunCommand(t, nil, "git", "-C", mirrorPath, "tag", "v1.2.0", "master") + testhelper.CreateTag(t, mirrorPath, "v1.2.0", "master", nil) newTagOid := string(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", "v1.0.0")) newTagOid = strings.TrimSpace(newTagOid) diff --git a/internal/testhelper/tag.go b/internal/testhelper/tag.go index 8ab0e64df..2abfd9dcf 100644 --- a/internal/testhelper/tag.go +++ b/internal/testhelper/tag.go @@ -11,16 +11,19 @@ import ( // CreateTagOpts holds extra options for CreateTag. type CreateTagOpts struct { Message string + Force bool } // CreateTag creates a new tag. func CreateTag(t *testing.T, repoPath, tagName, targetID string, opts *CreateTagOpts) string { var message string + force := false if opts != nil { if opts.Message != "" { message = opts.Message } + force = opts.Force } committerName := "Scrooge McDuck" @@ -34,6 +37,11 @@ func CreateTag(t *testing.T, repoPath, tagName, targetID string, opts *CreateTag "-c", fmt.Sprintf("user.email=%s", committerEmail), "tag", } + + if force { + args = append(args, "-f") + } + if message != "" { args = append(args, "-F", "-") } |