Skip to content

Commit

Permalink
Merge pull request #5 from uetchy/update-command
Browse files Browse the repository at this point in the history
Add new command 'update'
  • Loading branch information
uetchy committed Dec 25, 2015
2 parents 71bc337 + 88dd24c commit 601c619
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ List all of repositories changed git status

```console
gst
/Users/uetchy/repos/src/github.com/uetchy/cabret
/Users/uetchy/Repos/src/github.com/uetchy/cabret
-- 4 hours ago
A .eslintrc
M .gitignore
Expand All @@ -33,7 +33,7 @@ M index.html
M index.js
M package.json

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

```console
gst --short
/Users/uetchy/repos/src/github.com/uetchy/ferret
/Users/uetchy/repos/src/github.com/uetchy/gst
/Users/uetchy/Repos/src/github.com/uetchy/ferret
/Users/uetchy/Repos/src/github.com/uetchy/gst
```

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

```console
gst new awesome-project
/Users/uetchy/repos/src/github.com/uetchy/awesome-project
/Users/uetchy/Repos/src/github.com/uetchy/awesome-project
gst new epic-team/awesome-project
/Users/uetchy/repos/src/github.com/epic-team/awesome-project
/Users/uetchy/Repos/src/github.com/epic-team/awesome-project
```

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

```console
gst rm horrible-project
Remove? /Users/uetchy/repos/src/github.com/uetchy/horrible-project
Remove? /Users/uetchy/Repos/src/github.com/uetchy/horrible-project
```

### doctor
Expand All @@ -99,3 +99,13 @@ Health-check for repositories.
Expected: github.com/uetchy/google-cloud-vision-raspi-sample
Actual: bitbucket.org/uetchy/scent
```

### update

`git pull` for all repositories.

```console
gst update
/Users/uetchy/Repos/src/github.com/uetchy/gst
Already up-to-date.
```
13 changes: 3 additions & 10 deletions command_doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/codegangsta/cli"
// "github.com/daviddengcn/go-colortext"
// "github.com/dustin/go-humanize"
"os"
"strings"
)

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

func doDoctor(c *cli.Context) {
// fixupIssues := c.Bool("fixup")

ghqPath, err := getGhqPath()
if err != nil {
fmt.Println("You must setup ghq first")
os.Exit(1)
}

ghqPath := verifyGhqPath()
reposChannel := searchForRepos(ghqPath)

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

if remoteOriginURL == "" {
fmt.Println("["+source+"] 'remote.origin' doesn't exist:")
fmt.Println("[" + source + "] 'remote.origin' doesn't exist:")
fmt.Println(" Expected:\t", source)
fmt.Println(" Actual:\t (no remote)")
fmt.Println()
} else if target != source && !strings.Contains(source, "golang.org/x/") {
fmt.Println("["+source+"] 'remote.origin' has changed:")
fmt.Println("[" + source + "] 'remote.origin' has changed:")
fmt.Println(" Expected:\t", target)
fmt.Println(" Actual:\t", source)
// if fixupIssues {
Expand Down
10 changes: 2 additions & 8 deletions command_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/codegangsta/cli"
"github.com/daviddengcn/go-colortext"
"github.com/dustin/go-humanize"
"os"
"sort"
)

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

func doList(c *cli.Context) {
ghqPath, err := getGhqPath()
if err != nil {
fmt.Println("You must setup ghq first")
os.Exit(1)
}
ghqPath := verifyGhqPath()
reposChannel := searchForRepos(ghqPath)

shortExpression := c.Bool("short")

reposChannel := searchForRepos(ghqPath)

// Sort by time
repos := []Repository{}
for repo := range reposChannel {
Expand Down
34 changes: 34 additions & 0 deletions command_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"github.com/codegangsta/cli"
"github.com/daviddengcn/go-colortext"
)

var flagsOfUpdate = []cli.Flag{
cli.BoolFlag{
Name: "short, s",
Usage: "shorten result for pipeline processing",
},
}

var commandUpdate = cli.Command{
Name: "update",
Action: doUpdate,
Flags: flagsOfUpdate,
}

func doUpdate(c *cli.Context) {
ghqPath := verifyGhqPath()
repos := searchForRepos(ghqPath)

// Listing repos
for repo := range repos {
printlnWithColor(repo.Path, ct.Cyan)
err := GitPull(repo.Path)
if err != nil {
fmt.Println(err)
}
}
}
9 changes: 9 additions & 0 deletions ghq.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func (bmt RepositoriesByModTime) Less(i, j int) bool {
return bmt.Repositories[i].ModTime.Before(bmt.Repositories[j].ModTime)
}

func verifyGhqPath() string {
ghqPath, err := getGhqPath()
if err != nil {
fmt.Println("You must setup ghq first")
os.Exit(1)
}
return ghqPath
}

func getGhqPath() (string, error) {
out, err := exec.Command("ghq", "root").Output()
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"fmt"
"github.com/motemen/go-gitconfig"
"os"
"os/exec"
Expand Down Expand Up @@ -59,3 +60,18 @@ func GitStatus(targetPath string) ([]string, error) {

return statuses, nil
}

// GitPull pulls remote branch
func GitPull(targetPath string) error {
if err := os.Chdir(targetPath); err != nil {
return err
}

out, err := exec.Command("git", "pull").Output()
if err != nil {
return err
}

fmt.Println(string(out))
return nil
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
)

// Version of this program
var Version string = "HEAD"
var Version = "HEAD"

// Commands are list of available commands
var Commands = []cli.Command{
commandList,
commandNew,
commandRemove,
commandDoctor,
commandUpdate,
}

func main() {
Expand Down

0 comments on commit 601c619

Please sign in to comment.