Skip to content

Commit e75bb15

Browse files
authored
commit: author falls back to committer (#51)
* commit: author falls back to committer * Update Codecov settings * Adjust coverage range
1 parent 2c49687 commit e75bb15

File tree

4 files changed

+70
-45
lines changed

4 files changed

+70
-45
lines changed

appveyor.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

codecov.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
comment:
22
layout: 'diff, files'
3+
coverage:
4+
range: 60..95
5+
status:
6+
project:
7+
default:
8+
target: auto
9+
threshold: 1%
10+
base: auto

repo.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,10 @@ func RepoCommit(repoPath string, committer *Signature, message string, opts ...C
389389
cmd := NewCommand("commit")
390390
cmd.AddEnvs("GIT_COMMITTER_NAME="+committer.Name, "GIT_COMMITTER_EMAIL="+committer.Email)
391391

392-
if opt.Author != nil {
393-
cmd.AddArgs(fmt.Sprintf("--author='%s <%s>'", opt.Author.Name, opt.Author.Email))
392+
if opt.Author == nil {
393+
opt.Author = committer
394394
}
395+
cmd.AddArgs(fmt.Sprintf("--author='%s <%s>'", opt.Author.Name, opt.Author.Email))
395396
cmd.AddArgs("-m", message)
396397

397398
_, err := cmd.RunInDirWithTimeout(opt.Timeout, repoPath)

repo_test.go

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -348,37 +348,69 @@ func TestRepository_Commit(t *testing.T) {
348348
}
349349
})
350350

351-
// Generate a file and add to index
352-
fpath := filepath.Join(r.Path(), "TESTFILE")
353-
err = ioutil.WriteFile(fpath, []byte("something"), 0600)
354-
if err != nil {
355-
t.Fatal(err)
356-
}
351+
t.Run("committer is also the author", func(t *testing.T) {
352+
// Generate a file and add to index
353+
fpath := filepath.Join(r.Path(), "COMMITTER_IS_AUTHOR")
354+
err = ioutil.WriteFile(fpath, []byte("something"), 0600)
355+
if err != nil {
356+
t.Fatal(err)
357+
}
357358

358-
if err := r.Add(AddOptions{
359-
All: true,
360-
}); err != nil {
361-
t.Fatal(err)
362-
}
359+
if err := r.Add(AddOptions{
360+
All: true,
361+
}); err != nil {
362+
t.Fatal(err)
363+
}
363364

364-
// Make sure it does not blow up
365-
if err = r.Commit(committer, message, CommitOptions{
366-
Author: author,
367-
}); err != nil {
368-
t.Fatal(err)
369-
}
365+
// Make sure it does not blow up
366+
if err = r.Commit(committer, message); err != nil {
367+
t.Fatal(err)
368+
}
370369

371-
// Verify the result
372-
c, err := r.CatFileCommit("master")
373-
if err != nil {
374-
t.Fatal(err)
375-
}
370+
// Verify the result
371+
c, err := r.CatFileCommit("master")
372+
if err != nil {
373+
t.Fatal(err)
374+
}
375+
376+
assert.Equal(t, committer.Name, c.Committer.Name)
377+
assert.Equal(t, committer.Email, c.Committer.Email)
378+
assert.Equal(t, committer.Name, c.Author.Name)
379+
assert.Equal(t, committer.Email, c.Author.Email)
380+
assert.Equal(t, message+"\n", c.Message)
381+
})
382+
383+
t.Run("committer is not the author", func(t *testing.T) {
384+
// Generate a file and add to index
385+
fpath := filepath.Join(r.Path(), "COMMITTER_IS_NOT_AUTHOR")
386+
err = ioutil.WriteFile(fpath, []byte("something"), 0600)
387+
if err != nil {
388+
t.Fatal(err)
389+
}
390+
391+
if err := r.Add(AddOptions{
392+
All: true,
393+
}); err != nil {
394+
t.Fatal(err)
395+
}
396+
397+
// Make sure it does not blow up
398+
if err = r.Commit(committer, message, CommitOptions{Author: author}); err != nil {
399+
t.Fatal(err)
400+
}
376401

377-
assert.Equal(t, committer.Name, c.Committer.Name)
378-
assert.Equal(t, committer.Email, c.Committer.Email)
379-
assert.Equal(t, author.Name, c.Author.Name)
380-
assert.Equal(t, author.Email, c.Author.Email)
381-
assert.Equal(t, message+"\n", c.Message)
402+
// Verify the result
403+
c, err := r.CatFileCommit("master")
404+
if err != nil {
405+
t.Fatal(err)
406+
}
407+
408+
assert.Equal(t, committer.Name, c.Committer.Name)
409+
assert.Equal(t, committer.Email, c.Committer.Email)
410+
assert.Equal(t, author.Name, c.Author.Name)
411+
assert.Equal(t, author.Email, c.Author.Email)
412+
assert.Equal(t, message+"\n", c.Message)
413+
})
382414
}
383415

384416
func TestRepository_RevParse(t *testing.T) {

0 commit comments

Comments
 (0)