-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vcs): Correctly infer VCS settings when within a repo but not at…
- Loading branch information
Showing
10 changed files
with
203 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Package cli encompasses domain types for the CLI app. | ||
package cli | ||
|
||
// VCS represents a type of version control system. | ||
type VCS int | ||
|
||
const ( | ||
_ VCS = iota | ||
Subversion | ||
Git | ||
Mercurial | ||
Bazaar | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package vcs | ||
|
||
import ( | ||
"github.com/fossas/fossa-cli" | ||
"github.com/fossas/fossa-cli/files" | ||
"github.com/fossas/fossa-cli/monad" | ||
) | ||
|
||
// vcsFinder, bindVCSFinder, and friends are EitherVCS functions for finding whether | ||
// one of many files exist. | ||
type vcsFinder func(pathElems ...string) (bool, error) | ||
|
||
func bindVCSFinder(tool cli.VCS, find vcsFinder, pathElems ...string) monad.EitherVCSFunc { | ||
return func(prev cli.VCS) (cli.VCS, error) { | ||
ok, err := find(pathElems...) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if ok { | ||
return tool, nil | ||
} | ||
return prev, nil | ||
} | ||
} | ||
|
||
func findVCSFolder(tool cli.VCS, pathElems ...string) monad.EitherVCSFunc { | ||
return bindVCSFinder(tool, files.ExistsFolder, pathElems...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package vcs_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/fossas/fossa-cli/errutil" | ||
"github.com/fossas/fossa-cli/vcs" | ||
) | ||
|
||
func TestGetRepositoryAtRoot(t *testing.T) { | ||
wd, _ := os.Getwd() | ||
vcsDir, err := vcs.GetRepository(filepath.Join("testdata", "git")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, filepath.Join(wd, "testdata", "git"), vcsDir) | ||
} | ||
|
||
func TestGetRepositoryBelowRoot(t *testing.T) { | ||
wd, _ := os.Getwd() | ||
vcsDir, err := vcs.GetRepository(filepath.Join("testdata", "git", "nested", "directory")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, filepath.Join(wd, "testdata", "git"), vcsDir) | ||
} | ||
|
||
func TestGetRepositoryUnsupportedVCS(t *testing.T) { | ||
vcsDir, err := vcs.GetRepository(filepath.Join("testdata", "subversion", "nested", "directory")) | ||
assert.Error(t, err, errutil.ErrNotImplemented) | ||
assert.Equal(t, "", vcsDir) | ||
} |