Skip to content

Commit

Permalink
Merge pull request #89 from teezzan/fix/co-authors_not_cleared_from_m…
Browse files Browse the repository at this point in the history
…essage_template_on_switch
  • Loading branch information
davidalpert authored Oct 26, 2022
2 parents e3e8dac + 81b8c23 commit 7237c62
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: 🐛 co-authors not cleared from message template when returning to git solo

Background:
Given I have installed git-mob into "local_bin" within the current directory
And I look for executables in "local_bin" within the current directory

Given a file named "~/.gitconfig" with:
"""
[user]
name = Jane Doe
email = jane@example.com
"""

And a file named "~/.git-coauthors" with:
"""
{
"coauthors": {
"ad": {
"name": "Amy Doe",
"email": "amy@findmypast.com"
},
"bd": {
"name": "Bob Doe",
"email": "bob@findmypast.com"
}
}
}
"""

Scenario:
Given I successfully run `git mob ad`
And the file "~/.gitmessage" should contain:
"""
Co-authored-by: Amy Doe <amy@findmypast.com>
"""
When I successfully run `git solo`
And the file "~/.gitmessage" should not contain "Co-authored-by"
19 changes: 3 additions & 16 deletions internal/cmd/mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package cmd
import (
"errors"
"fmt"
"sort"
"strings"

"github.com/davidalpert/go-git-mob/internal/authors"
"github.com/davidalpert/go-git-mob/internal/gitCommands"
"github.com/davidalpert/go-git-mob/internal/gitConfig"
Expand All @@ -12,8 +15,6 @@ import (
"github.com/davidalpert/go-printers/v1"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"sort"
"strings"
)

type MobOptions struct {
Expand Down Expand Up @@ -163,13 +164,6 @@ func (o *MobOptions) runMob() error {
if err := o.printMob(); err != nil {
return err
}
if gitCommands.UsingLocalTemplate() && gitMobCommands.IsCoAuthorsSet() {
if coauthors, err := gitMobCommands.GetCoAuthors(); err != nil {
return err
} else {
return gitMessage.Write(gitMessage.Path(), coauthors...)
}
}
return nil
}

Expand Down Expand Up @@ -289,13 +283,6 @@ func (o *MobOptions) setMob() error {
if err := gitMobCommands.AddCoAuthors(coauthors...); err != nil {
return fmt.Errorf("AddCoAuthors: %v", err)
}
if err := gitMessage.Write(gitMessage.Path(), coauthors...); err != nil {
return fmt.Errorf("WriteGitMessage: %v", err)
}

if gitCommands.UsingLocalTemplate() && gitCommands.UsingGlobalTemplate() {
gitMessage.Write(gitCommands.GetGlobalTemplate(), coauthors...)
}

return o.printMob()
}
Expand Down

0 comments on commit 7237c62

Please sign in to comment.