Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit e8ff70d

Browse files
authored
Merge pull request #38 from imikushin/fix-messing-up-project-dir
Fix messing up project dir
2 parents be4b321 + 40e4a6a commit e8ff70d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5058
-1622
lines changed

trash.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# package
44
github.com/rancher/trash
55

6-
github.com/Sirupsen/logrus v0.9.0
7-
github.com/codegangsta/cli v1.2.0
8-
github.com/cloudfoundry-incubator/candiedyaml 4e924c7
6+
github.com/Sirupsen/logrus v0.10.0
7+
github.com/urfave/cli v1.18.0
8+
github.com/cloudfoundry-incubator/candiedyaml 99c3df8
99
github.com/stretchr/testify v1.1.3
1010
github.com/davecgh/go-spew 5215b55
1111
github.com/pmezard/go-difflib 792786c
12-
golang.org/x/sys 076b546
12+
golang.org/x/sys a408501

trash.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
"strings"
1414

1515
"github.com/Sirupsen/logrus"
16-
"github.com/codegangsta/cli"
16+
"github.com/urfave/cli"
17+
1718
"github.com/rancher/trash/conf"
1819
"github.com/rancher/trash/util"
1920
)
@@ -61,11 +62,9 @@ func main() {
6162
EnvVar: "TRASH_CACHE",
6263
},
6364
}
64-
app.Action = func(c *cli.Context) {
65-
exit(run(c))
66-
}
65+
app.Action = run
6766

68-
exit(app.Run(os.Args))
67+
app.Run(os.Args)
6968
}
7069

7170
func run(c *cli.Context) error {
@@ -79,10 +78,15 @@ func run(c *cli.Context) error {
7978
update := c.Bool("update")
8079
trashDir := c.String("cache")
8180

81+
trashDir, err := filepath.Abs(trashDir)
82+
if err != nil {
83+
return err
84+
}
85+
8286
if err := os.Chdir(dir); err != nil {
8387
return err
8488
}
85-
dir, err := os.Getwd()
89+
dir, err = os.Getwd()
8690
if err != nil {
8791
return err
8892
}
@@ -331,8 +335,7 @@ func checkGitRepo(trashDir, repoDir string, i conf.Import) error {
331335
return err
332336
}
333337
}
334-
if bytes, err := exec.Command("git", "status").CombinedOutput(); err != nil {
335-
logrus.WithFields(logrus.Fields{"err": err}).Warnf("`git status` failed:\n%s", bytes)
338+
if !isCurrentDirARepo(trashDir) {
336339
os.Chdir(trashDir)
337340
return cloneGitRepo(trashDir, repoDir, i)
338341
}
@@ -344,6 +347,19 @@ func checkGitRepo(trashDir, repoDir string, i conf.Import) error {
344347
return nil
345348
}
346349

350+
func isCurrentDirARepo(trashDir string) bool {
351+
d, err := os.Getwd()
352+
if err != nil {
353+
logrus.Fatalf("Error getting current dir: %s", err)
354+
}
355+
bytes, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
356+
if err != nil {
357+
logrus.Debugf("Not in a git repo: `git rev-parse --show-toplevel` in dir %s failed: %s", d, err)
358+
return false
359+
}
360+
return strings.HasPrefix(string(bytes), trashDir+"/src/")
361+
}
362+
347363
func remoteExists(remoteName string) bool {
348364
lines := util.CmdOutLines(exec.Command("git", "remote"))
349365
for line := range lines {
@@ -389,8 +405,8 @@ func cloneGitRepo(trashDir, repoDir string, i conf.Import) error {
389405
return err
390406
}
391407
os.Chdir(repoDir)
392-
if err := exec.Command("git", "status").Run(); err != nil {
393-
logrus.WithFields(logrus.Fields{"err": err, "repoDir": repoDir}).Debug("not a git repo, creating one")
408+
if !isCurrentDirARepo(trashDir) {
409+
logrus.WithFields(logrus.Fields{"repoDir": repoDir}).Debug("not a git repo, creating one")
394410
exec.Command("git", "init", "-q").Run()
395411
}
396412
if i.Repo != "" {

vendor/github.com/Sirupsen/logrus/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Sirupsen/logrus/README.md

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Sirupsen/logrus/entry.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Sirupsen/logrus/logrus.go

Lines changed: 46 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloudfoundry-incubator/candiedyaml/LICENSE

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloudfoundry-incubator/candiedyaml/README.md

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloudfoundry-incubator/candiedyaml/decode.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloudfoundry-incubator/candiedyaml/emitter.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)