Skip to content

Commit

Permalink
Handle no conflict error
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 31, 2017
1 parent 4dd10fd commit 2e3a0b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
14 changes: 14 additions & 0 deletions conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ type Conflict struct {
displayDiff bool
}

type ErrNoConflict struct {
message string
}

func NewErrNoConflict(message string) *ErrNoConflict {
return &ErrNoConflict{
message: message,
}
}

func (e *ErrNoConflict) Error() string {
return e.message
}

const (
Local = 1
Incoming = 2
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ func main() {
var err error
conflicts, err = Find()
if err != nil {
log.Panicln("No conflicts found")
switch err.(type) {
case *ErrNoConflict:
fmt.Println(Green(Regular, err.Error()))
return
default:
log.Panicln(err)
}
}
conflictCount = len(conflicts)

Expand Down
8 changes: 4 additions & 4 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func Find() ([]Conflict, error) {

cmdOut, err = cmd.Output()
if !(strings.Contains(err.Error(), "exit status 2")) {
return nil, err
return nil, NewErrNoConflict("No conflicts detected 🎉")
}

output := bytes.Split(cmdOut, []byte("\n"))
Expand All @@ -178,17 +178,17 @@ func Find() ([]Conflict, error) {
conflicts = append(conflicts, c)
}
} else {
log.Panic(err)
return nil, err
}
}

allFileLines = make(map[string][]string)
for i := range conflicts {
if err := conflicts[i].ExtractLines(); err != nil {
log.Panicln(err)
return nil, err
}
if err := conflicts[i].Highlight(); err != nil {
log.Println(err)
return nil, err
}
}

Expand Down

0 comments on commit 2e3a0b7

Please sign in to comment.