Skip to content

Commit 601c619

Browse files
committed
Merge pull request #5 from uetchy/update-command
Add new command 'update'
2 parents 71bc337 + 88dd24c commit 601c619

File tree

7 files changed

+83
-26
lines changed

7 files changed

+83
-26
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ List all of repositories changed git status
2121

2222
```console
2323
gst
24-
/Users/uetchy/repos/src/github.com/uetchy/cabret
24+
/Users/uetchy/Repos/src/github.com/uetchy/cabret
2525
-- 4 hours ago
2626
A .eslintrc
2727
M .gitignore
@@ -33,7 +33,7 @@ M index.html
3333
M index.js
3434
M package.json
3535

36-
/Users/uetchy/repos/src/github.com/uetchy/gst
36+
/Users/uetchy/Repos/src/github.com/uetchy/gst
3737
-- 3 minutes ago
3838
A changelog.md
3939
R gst.go -> main.go
@@ -43,8 +43,8 @@ with __--short__ option:
4343

4444
```console
4545
gst --short
46-
/Users/uetchy/repos/src/github.com/uetchy/ferret
47-
/Users/uetchy/repos/src/github.com/uetchy/gst
46+
/Users/uetchy/Repos/src/github.com/uetchy/ferret
47+
/Users/uetchy/Repos/src/github.com/uetchy/gst
4848
```
4949

5050
You can also use `peco` for pipeline processing as:
@@ -61,9 +61,9 @@ Before start using 'new' and 'rm' command, You __must__ set 'github.user' to .gi
6161

6262
```console
6363
gst new awesome-project
64-
/Users/uetchy/repos/src/github.com/uetchy/awesome-project
64+
/Users/uetchy/Repos/src/github.com/uetchy/awesome-project
6565
gst new epic-team/awesome-project
66-
/Users/uetchy/repos/src/github.com/epic-team/awesome-project
66+
/Users/uetchy/Repos/src/github.com/epic-team/awesome-project
6767
```
6868

6969
with `cd`, You can jump to created project:
@@ -86,7 +86,7 @@ Remove git repository.
8686

8787
```console
8888
gst rm horrible-project
89-
Remove? /Users/uetchy/repos/src/github.com/uetchy/horrible-project
89+
Remove? /Users/uetchy/Repos/src/github.com/uetchy/horrible-project
9090
```
9191

9292
### doctor
@@ -99,3 +99,13 @@ Health-check for repositories.
9999
Expected: github.com/uetchy/google-cloud-vision-raspi-sample
100100
Actual: bitbucket.org/uetchy/scent
101101
```
102+
103+
### update
104+
105+
`git pull` for all repositories.
106+
107+
```console
108+
gst update
109+
/Users/uetchy/Repos/src/github.com/uetchy/gst
110+
Already up-to-date.
111+
```

command_doctor.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/codegangsta/cli"
66
// "github.com/daviddengcn/go-colortext"
77
// "github.com/dustin/go-humanize"
8-
"os"
98
"strings"
109
)
1110

@@ -22,13 +21,7 @@ var commandDoctor = cli.Command{
2221

2322
func doDoctor(c *cli.Context) {
2423
// fixupIssues := c.Bool("fixup")
25-
26-
ghqPath, err := getGhqPath()
27-
if err != nil {
28-
fmt.Println("You must setup ghq first")
29-
os.Exit(1)
30-
}
31-
24+
ghqPath := verifyGhqPath()
3225
reposChannel := searchForRepos(ghqPath)
3326

3427
// Listing repos
@@ -38,12 +31,12 @@ func doDoctor(c *cli.Context) {
3831
source := strings.TrimPrefix(repo.Path, ghqPath+"/")
3932

4033
if remoteOriginURL == "" {
41-
fmt.Println("["+source+"] 'remote.origin' doesn't exist:")
34+
fmt.Println("[" + source + "] 'remote.origin' doesn't exist:")
4235
fmt.Println(" Expected:\t", source)
4336
fmt.Println(" Actual:\t (no remote)")
4437
fmt.Println()
4538
} else if target != source && !strings.Contains(source, "golang.org/x/") {
46-
fmt.Println("["+source+"] 'remote.origin' has changed:")
39+
fmt.Println("[" + source + "] 'remote.origin' has changed:")
4740
fmt.Println(" Expected:\t", target)
4841
fmt.Println(" Actual:\t", source)
4942
// if fixupIssues {

command_list.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/codegangsta/cli"
66
"github.com/daviddengcn/go-colortext"
77
"github.com/dustin/go-humanize"
8-
"os"
98
"sort"
109
)
1110

@@ -23,16 +22,11 @@ var commandList = cli.Command{
2322
}
2423

2524
func doList(c *cli.Context) {
26-
ghqPath, err := getGhqPath()
27-
if err != nil {
28-
fmt.Println("You must setup ghq first")
29-
os.Exit(1)
30-
}
25+
ghqPath := verifyGhqPath()
26+
reposChannel := searchForRepos(ghqPath)
3127

3228
shortExpression := c.Bool("short")
3329

34-
reposChannel := searchForRepos(ghqPath)
35-
3630
// Sort by time
3731
repos := []Repository{}
3832
for repo := range reposChannel {

command_update.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
"github.com/daviddengcn/go-colortext"
7+
)
8+
9+
var flagsOfUpdate = []cli.Flag{
10+
cli.BoolFlag{
11+
Name: "short, s",
12+
Usage: "shorten result for pipeline processing",
13+
},
14+
}
15+
16+
var commandUpdate = cli.Command{
17+
Name: "update",
18+
Action: doUpdate,
19+
Flags: flagsOfUpdate,
20+
}
21+
22+
func doUpdate(c *cli.Context) {
23+
ghqPath := verifyGhqPath()
24+
repos := searchForRepos(ghqPath)
25+
26+
// Listing repos
27+
for repo := range repos {
28+
printlnWithColor(repo.Path, ct.Cyan)
29+
err := GitPull(repo.Path)
30+
if err != nil {
31+
fmt.Println(err)
32+
}
33+
}
34+
}

ghq.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ func (bmt RepositoriesByModTime) Less(i, j int) bool {
4141
return bmt.Repositories[i].ModTime.Before(bmt.Repositories[j].ModTime)
4242
}
4343

44+
func verifyGhqPath() string {
45+
ghqPath, err := getGhqPath()
46+
if err != nil {
47+
fmt.Println("You must setup ghq first")
48+
os.Exit(1)
49+
}
50+
return ghqPath
51+
}
52+
4453
func getGhqPath() (string, error) {
4554
out, err := exec.Command("ghq", "root").Output()
4655
if err != nil {

git.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"errors"
5+
"fmt"
56
"github.com/motemen/go-gitconfig"
67
"os"
78
"os/exec"
@@ -59,3 +60,18 @@ func GitStatus(targetPath string) ([]string, error) {
5960

6061
return statuses, nil
6162
}
63+
64+
// GitPull pulls remote branch
65+
func GitPull(targetPath string) error {
66+
if err := os.Chdir(targetPath); err != nil {
67+
return err
68+
}
69+
70+
out, err := exec.Command("git", "pull").Output()
71+
if err != nil {
72+
return err
73+
}
74+
75+
fmt.Println(string(out))
76+
return nil
77+
}

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66
)
77

88
// Version of this program
9-
var Version string = "HEAD"
9+
var Version = "HEAD"
1010

1111
// Commands are list of available commands
1212
var Commands = []cli.Command{
1313
commandList,
1414
commandNew,
1515
commandRemove,
1616
commandDoctor,
17+
commandUpdate,
1718
}
1819

1920
func main() {

0 commit comments

Comments
 (0)