Skip to content

Commit

Permalink
Move check for a git repository (#9)
Browse files Browse the repository at this point in the history
Using the `Before` function we avoid having the same check duplicated in
all commands.
  • Loading branch information
alissonbrunosa authored May 30, 2023
1 parent 5804813 commit fbdff27
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
5 changes: 0 additions & 5 deletions cmd/git-pair/end.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
)

func End() {
if !git.IsGitRepo() {
fmt.Println("Not executed from a git repository")
return
}

err := git.DisablePairingMode()

if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions cmd/git-pair/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
)

func Info() {
if !git.IsGitRepo() {
fmt.Println("Not executed from a git repository")
return
}

if !git.PairingModeEnabled() {
fmt.Println("Pairing mode is not enabled")
return
Expand Down
9 changes: 9 additions & 0 deletions cmd/git-pair/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"errors"
"fmt"
"log"
"os"

"github.com/inverse/git-pair/internal/diagnostics"
"github.com/inverse/git-pair/internal/git"
"github.com/urfave/cli/v2"
)

Expand All @@ -17,6 +19,13 @@ func main() {
app := &cli.App{
Version: diagnostics.Version,
Usage: "A tool to make it easier for git based pairing for co-authoring commits",
Before: func(cCtx *cli.Context) error {
if !git.IsGitRepo() {
return errors.New("Not executed from a git repository")
}

return nil
},
Commands: []*cli.Command{
{
Name: "start",
Expand Down
5 changes: 0 additions & 5 deletions cmd/git-pair/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
)

func Start() {
if !git.IsGitRepo() {
fmt.Println("Not executed from a git repository")
return
}

localContributors, err := contributors.GetLocalContributors()
if err != nil {
fmt.Printf("Failed to load local contributors: %s\n", err)
Expand Down

0 comments on commit fbdff27

Please sign in to comment.