diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 08c6a99a1..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "{build}" -skip_tags: true -clone_folder: c:\github.com\gogs\git-module -clone_depth: 1 - -environment: - GO111MODULE: on - GOPROXY: https://proxy.golang.org - -build: false -deploy: false - -install: - - go version - - go env - - go test -v -cover -race -verbose \ No newline at end of file diff --git a/codecov.yml b/codecov.yml index 285498b69..e20384852 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,10 @@ comment: layout: 'diff, files' +coverage: + range: 60..95 + status: + project: + default: + target: auto + threshold: 1% + base: auto diff --git a/repo.go b/repo.go index c55df661e..edb97dc64 100644 --- a/repo.go +++ b/repo.go @@ -389,9 +389,10 @@ func RepoCommit(repoPath string, committer *Signature, message string, opts ...C cmd := NewCommand("commit") cmd.AddEnvs("GIT_COMMITTER_NAME="+committer.Name, "GIT_COMMITTER_EMAIL="+committer.Email) - if opt.Author != nil { - cmd.AddArgs(fmt.Sprintf("--author='%s <%s>'", opt.Author.Name, opt.Author.Email)) + if opt.Author == nil { + opt.Author = committer } + cmd.AddArgs(fmt.Sprintf("--author='%s <%s>'", opt.Author.Name, opt.Author.Email)) cmd.AddArgs("-m", message) _, err := cmd.RunInDirWithTimeout(opt.Timeout, repoPath) diff --git a/repo_test.go b/repo_test.go index 966dbdee8..6d75cdfd3 100644 --- a/repo_test.go +++ b/repo_test.go @@ -348,37 +348,69 @@ func TestRepository_Commit(t *testing.T) { } }) - // Generate a file and add to index - fpath := filepath.Join(r.Path(), "TESTFILE") - err = ioutil.WriteFile(fpath, []byte("something"), 0600) - if err != nil { - t.Fatal(err) - } + t.Run("committer is also the author", func(t *testing.T) { + // Generate a file and add to index + fpath := filepath.Join(r.Path(), "COMMITTER_IS_AUTHOR") + err = ioutil.WriteFile(fpath, []byte("something"), 0600) + if err != nil { + t.Fatal(err) + } - if err := r.Add(AddOptions{ - All: true, - }); err != nil { - t.Fatal(err) - } + if err := r.Add(AddOptions{ + All: true, + }); err != nil { + t.Fatal(err) + } - // Make sure it does not blow up - if err = r.Commit(committer, message, CommitOptions{ - Author: author, - }); err != nil { - t.Fatal(err) - } + // Make sure it does not blow up + if err = r.Commit(committer, message); err != nil { + t.Fatal(err) + } - // Verify the result - c, err := r.CatFileCommit("master") - if err != nil { - t.Fatal(err) - } + // Verify the result + c, err := r.CatFileCommit("master") + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, committer.Name, c.Committer.Name) + assert.Equal(t, committer.Email, c.Committer.Email) + assert.Equal(t, committer.Name, c.Author.Name) + assert.Equal(t, committer.Email, c.Author.Email) + assert.Equal(t, message+"\n", c.Message) + }) + + t.Run("committer is not the author", func(t *testing.T) { + // Generate a file and add to index + fpath := filepath.Join(r.Path(), "COMMITTER_IS_NOT_AUTHOR") + err = ioutil.WriteFile(fpath, []byte("something"), 0600) + if err != nil { + t.Fatal(err) + } + + if err := r.Add(AddOptions{ + All: true, + }); err != nil { + t.Fatal(err) + } + + // Make sure it does not blow up + if err = r.Commit(committer, message, CommitOptions{Author: author}); err != nil { + t.Fatal(err) + } - assert.Equal(t, committer.Name, c.Committer.Name) - assert.Equal(t, committer.Email, c.Committer.Email) - assert.Equal(t, author.Name, c.Author.Name) - assert.Equal(t, author.Email, c.Author.Email) - assert.Equal(t, message+"\n", c.Message) + // Verify the result + c, err := r.CatFileCommit("master") + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, committer.Name, c.Committer.Name) + assert.Equal(t, committer.Email, c.Committer.Email) + assert.Equal(t, author.Name, c.Author.Name) + assert.Equal(t, author.Email, c.Author.Email) + assert.Equal(t, message+"\n", c.Message) + }) } func TestRepository_RevParse(t *testing.T) {