Skip to content

Commit 9368c33

Browse files
committed
close #192 move git commands to new configuration
1 parent 4aa91b7 commit 9368c33

File tree

20 files changed

+558
-543
lines changed

20 files changed

+558
-543
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ maintainer: groenborg
66

77
| tollgate | build | goreport | coveralls | issues |
88
| ------------- | --- | ----------------- | ----- | ----- |
9-
| ![integration status](https://concourse.bosh.praqma.cloud/api/v1/teams/main/pipelines/git-phlow/jobs/integration-test/badge) | ![build status](https://concourse.bosh.praqma.cloud/api/v1/teams/main/pipelines/git-phlow/jobs/shipit/badge) |[![Go Report Card](https://goreportcard.com/badge/github.com/Praqma/git-phlow)](https://goreportcard.com/report/github.com/Praqma/git-phlow) | [![Coverage Status](https://coveralls.io/repos/github/Praqma/git-phlow/badge.svg?branch=master)](https://coveralls.io/github/Praqma/git-phlow?branch=master) | [![Stories in Ready](https://badge.waffle.io/Praqma/git-phlow.svg?label=ready&title=Ready)](http://waffle.io/Praqma/git-phlow) |
9+
| ![integration status](https://concourse.bosh.praqma.cloud/api/v1/teams/main/pipelines/git-phlow/jobs/checkin/badge) | ![build status](https://concourse.bosh.praqma.cloud/api/v1/teams/main/pipelines/git-phlow/jobs/takeoff/badge) |[![Go Report Card](https://goreportcard.com/badge/github.com/Praqma/git-phlow)](https://goreportcard.com/report/github.com/Praqma/git-phlow) | [![Coverage Status](https://coveralls.io/repos/github/Praqma/git-phlow/badge.svg?branch=master)](https://coveralls.io/github/Praqma/git-phlow?branch=master) | [![Stories in Ready](https://badge.waffle.io/Praqma/git-phlow.svg?label=ready&title=Ready)](http://waffle.io/Praqma/git-phlow) |
1010

1111

1212
git-phlow (pronounced _"git flow"_), is a CLI extension for git, which provides an extra set of commands to easily use our pragmatic workflow called **the phlow**. It provides a branching model which makes collaboration easy. It also provides automatic issue tracking using [GitHub](https://github.com) issues with [Waffle](https://waffle.io/). The branching model uses branches prefixed with `ready` (can be configured) to mark delivered tasks to the remote repository from where automation services can pick up and integrate the changes into the stable branch.

cmd/cmdperm/prerunperm.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/praqma/git-phlow/githandler"
88
"github.com/praqma/git-phlow/ui"
99
"github.com/praqma/git-phlow/setting"
10+
"github.com/praqma/git-phlow/executor"
1011
)
1112

1213
//RequiredAuthentication ...
@@ -25,7 +26,8 @@ func RequiredAuthentication() {
2526
//RequiredCurDirRepository ...
2627
//Validates if the command is runnign in a git repository
2728
func RequiredCurDirRepository() {
28-
if err := githandler.Status(); err != nil {
29+
git := githandler.Git{Run: executor.RunGit}
30+
if _, err := git.Status(); err != nil {
2931
fmt.Fprintln(os.Stdout, err)
3032
os.Exit(0)
3133
}

executor/executor.go

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os/exec"
88

99
"github.com/praqma/git-phlow/options"
10-
"io"
1110
)
1211

1312
//verboseOutput ...
@@ -36,14 +35,13 @@ func ExecuteCommander(c Commander) error {
3635
return nil
3736
}
3837

39-
4038
//Runner ...
4139
//Runner type for git executions
4240
type Runner func(command string, argv ...string) (string, error)
4341

4442
//Run ...
4543
//implemented runner
46-
func Run(command string, argv ...string) (string, error) {
44+
func RunCommand(command string, argv ...string) (string, error) {
4745
var stdOutBuffer, stdErrBuffer bytes.Buffer
4846
exe := exec.Command(command, argv...)
4947

@@ -64,10 +62,15 @@ func Run(command string, argv ...string) (string, error) {
6462
return stdOutBuffer.String(), nil
6563
}
6664

65+
//GitCommandRunner ...
66+
type GitCommandRunner func(git string, sub string, argv ...string) (string, error)
67+
6768
//ExecuteCommand ...
6869
//Executes a single command from strings
69-
func ExecuteCommand(command string, argv ...string) (string, error) {
70-
exe := exec.Command(command, argv...)
70+
func RunGit(git string, sub string, argv ...string) (string, error) {
71+
72+
argv = append([]string{sub}, argv...)
73+
exe := exec.Command(git, argv...)
7174

7275
if options.GlobalFlagVerbose {
7376
verboseOutput(exe.Args...)
@@ -91,63 +94,3 @@ func ExecuteCommand(command string, argv ...string) (string, error) {
9194

9295
return stdOutBuffer.String(), nil
9396
}
94-
95-
//ExecPipeCommand ...
96-
//Executes a series of commands
97-
func ExecPipeCommand(out *bytes.Buffer, execStack ...*exec.Cmd) (err error) {
98-
99-
var errBuf bytes.Buffer
100-
101-
pipes := make([]*io.PipeWriter, len(execStack)-1)
102-
execStack[len(execStack)-1].Stdout = out
103-
104-
for i := 0; i < len(execStack)-1; i++ {
105-
r, w := io.Pipe()
106-
execStack[i].Stdout = w
107-
execStack[i].Stderr = &errBuf
108-
execStack[i+1].Stdin = r
109-
pipes[i] = w
110-
111-
}
112-
113-
for i := 0; i < len(execStack); i++ {
114-
if options.GlobalFlagVerbose {
115-
verboseOutput(execStack[i].Args...)
116-
}
117-
118-
if err = execStack[i].Start(); err != nil {
119-
return
120-
}
121-
}
122-
123-
if err = closer(pipes, execStack); err != nil {
124-
return
125-
}
126-
127-
return nil
128-
}
129-
130-
//closer ...
131-
//helper function to ExecutePipeCommand
132-
func closer(pipes []*io.PipeWriter, execStack []*exec.Cmd) (err error) {
133-
//Return if the command-stack is empty
134-
if len(execStack) <= 0 {
135-
return nil
136-
}
137-
138-
defer func() {
139-
//Close the pipe if more exists
140-
if len(pipes) > 0 {
141-
if err = pipes[0].Close(); err != nil {
142-
return
143-
}
144-
pipes = pipes[1:]
145-
}
146-
if err = closer(pipes, execStack[1:]); err != nil {
147-
return
148-
}
149-
}()
150-
//Wait for the command to return, defer is the
151-
//last function to be executed
152-
return execStack[0].Wait()
153-
}

executor/executor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ var _ = Describe("Executor", func() {
1414

1515
Context("called with valid command ls", func() {
1616
It("should not return an error", func() {
17-
_, err := ExecuteCommand("git", "--version")
17+
_, err := RunCommand("git", "--version")
1818

1919
Ω(err).Should(BeNil())
2020
})
2121
})
2222

2323
Context("called with invalid command", func() {
2424
It("should fail", func() {
25-
output, err := ExecuteCommand("lsk", "-lah")
25+
output, err := RunCommand("lsk", "-lah")
2626
Ω(output).Should(BeEmpty())
2727
Ω(err).ShouldNot(BeNil())
2828
})

githandler/branch.go

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,26 @@ type BranchInfo struct {
1313
List []string
1414
}
1515

16-
func RemoteBranch() (remote string) {
17-
remote, err := executor.ExecuteCommand("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")
18-
if err != nil {
19-
return ""
20-
}
21-
return
22-
}
23-
24-
//Branch ...
25-
func Branch() (*BranchInfo, error) {
26-
var err error
27-
info := BranchInfo{}
16+
//AsList ...
17+
func AsList(branchOutput string) *BranchInfo {
18+
var info BranchInfo
2819

29-
current, cErr := executor.ExecuteCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
30-
if cErr != nil {
31-
return nil, err
32-
}
33-
34-
output, lErr := executor.ExecuteCommand("git", "branch", "-a")
35-
if lErr != nil {
36-
return nil, err
37-
}
38-
39-
info.Current = strings.TrimSpace(current)
40-
for _, branch := range strings.Split(output, "\n") {
20+
for _, branch := range strings.Split(branchOutput, "\n") {
4121
if branch != "" {
42-
branch = strings.TrimPrefix(branch, "*")
22+
if strings.HasPrefix(branch, "*") {
23+
branch = strings.TrimPrefix(branch, "*")
24+
branch = strings.TrimSpace(branch)
25+
info.Current = branch
26+
}
4327
branch = strings.TrimSpace(branch)
4428
info.List = append(info.List, branch)
4529
}
4630
}
47-
return &info, err
48-
}
49-
50-
//BranchRename ...
51-
func BranchRename(name string) error {
52-
_, err := executor.ExecuteCommand("git", "branch", "-m", name, "delivered/"+name)
53-
return err
54-
}
55-
56-
//BranchDelete ...
57-
func BranchDelete(name, remote string, deleteRemote, force bool) (string, error) {
58-
if deleteRemote {
59-
return executor.ExecuteCommand("git", "push", remote, "--delete", name)
60-
}
61-
62-
if force {
63-
return executor.ExecuteCommand("git", "branch", "-D", name)
64-
}
65-
return executor.ExecuteCommand("git", "branch", "-d", name)
31+
return &info
6632
}
6733

68-
//BranchDelivered ...
69-
func BranchDelivered(remote string) (localBranches []string, remoteBranches []string) {
70-
info, err := Branch()
71-
72-
if err != nil {
73-
return
74-
}
34+
//Delivered ...
35+
func Delivered(info *BranchInfo, remote string) (localBranches []string, remoteBranches []string) {
7536

7637
for _, branch := range info.List {
7738
if strings.HasPrefix(branch, "delivered/") {
@@ -85,21 +46,8 @@ func BranchDelivered(remote string) (localBranches []string, remoteBranches []st
8546
return
8647
}
8748

88-
func branchRemote() (string, error) {
89-
output, err := executor.ExecuteCommand("git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")
90-
if err != nil {
91-
return "", err
92-
}
93-
return strings.TrimSpace(output), nil
94-
}
95-
96-
//BranchReady ...
97-
func BranchReady(remote string, prefix string) (remoteBranches []string) {
98-
info, err := Branch()
99-
if err != nil {
100-
return
101-
}
102-
49+
//Ready ...
50+
func Ready(info *BranchInfo, remote string, prefix string) (remoteBranches []string) {
10351
for _, branch := range info.List {
10452
if strings.HasPrefix(branch, "remotes/"+remote+"/"+prefix) {
10553
branch = strings.TrimPrefix(branch, "remotes/")
@@ -109,9 +57,19 @@ func BranchReady(remote string, prefix string) (remoteBranches []string) {
10957
return
11058
}
11159

60+
61+
62+
63+
//DEPRECETED SECTION - USE GIT
64+
//BranchRename ...
65+
func BranchRename(name string) error {
66+
_, err := executor.RunCommand("git", "branch", "-m", name, "delivered/"+name)
67+
return err
68+
}
69+
11270
//BranchTime ...
11371
func BranchTime(name string) (int, error) {
114-
output, err := executor.ExecuteCommand("git", "log", "-n 1", name, "--format=format:%ct")
72+
output, err := executor.RunCommand("git", "log", "-n 1", name, "--format=format:%ct")
11573
if err != nil {
11674
return -1, err
11775
}

0 commit comments

Comments
 (0)