Skip to content

Commit

Permalink
Remove git helper for finish
Browse files Browse the repository at this point in the history
Signed-off-by: Dominic Cassidy <dominic@koroutine.tech>
  • Loading branch information
Drache93 committed Mar 17, 2022
1 parent 38f3d25 commit bfcf9ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
34 changes: 7 additions & 27 deletions cmd/finish.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"regexp"
"strconv"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/bitfield/script"
"github.com/koroutine/pvtg/pivotal"
"github.com/spf13/cobra"
)
Expand All @@ -31,23 +30,16 @@ merge into 'dev' branch and finish the story`,
project, err := client.SelectProject(projectName)
CheckIfError(err)

fmt.Println("Opening repo at", dir)
r, err := git.PlainOpen(dir)
CheckIfError(err)

w, err := r.Worktree()
CheckIfError(err)
fmt.Println("Using repo at", dir)

headRef, err := r.Head()
branchName, err := script.Exec("git rev-parse --abbrev-ref HEAD").String()
CheckIfError(err)

if !headRef.Name().IsBranch() {
if branchName == "HEAD" {
CheckIfError(errors.New("repository head is not on a branch"))
}

branchName := headRef.Name().Short()
re := regexp.MustCompile(`^(\d{9})_`)

result := re.FindStringSubmatch(branchName)

if len(result) != 2 {
Expand All @@ -61,27 +53,15 @@ merge into 'dev' branch and finish the story`,
CheckIfError(err)

// Get repo status
status, err := w.Status()
changes, err := script.Exec("git status --porcelain").String()
CheckIfError(err)

if !status.IsClean() {
if changes != "" {
CheckIfError(fmt.Errorf("branch '%s' has uncommitted changes", branchName))
}

// Checkout dev
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.ReferenceName(plumbing.NewBranchReferenceName("dev")),
Force: true,
})

if errors.Is(err, git.ErrBranchNotFound) {
CheckIfError(errors.New("dev branch not found"))
// TODO prompt to make dev branch
} else {
CheckIfError(err)
}

gitCmds := [][]string{
{"checkout", "dev"},
{"merge", branchName},
{"push"},
{"branch", "-d", branchName},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module github.com/koroutine/pvtg
go 1.17

require (
bitbucket.org/creachadair/shell v0.0.7 // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/bitfield/script v0.18.5 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bitbucket.org/creachadair/shell v0.0.7 h1:Z96pB6DkSb7F3Y3BBnJeOZH2gazyMTWlvecSD4vDqfk=
bitbucket.org/creachadair/shell v0.0.7/go.mod h1:oqtXSSvSYr4624lnnabXHaBsYW6RD80caLi2b3hJk0U=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down Expand Up @@ -73,6 +75,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bitfield/script v0.18.5 h1:H2MF62P+do3Am9vdjssiI62AZwp5a/Svl1Dy6FO7gVQ=
github.com/bitfield/script v0.18.5/go.mod h1:1fgtfwQE664tyKhBcY//qngbPvKDziFBzTSr5IE+U4M=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down

0 comments on commit bfcf9ff

Please sign in to comment.