@@ -571,41 +571,54 @@ func CreateFromDir(w io.Writer, m module.Version, dir string) (err error) {
571571// CreateFromVCS creates a module zip file for module m from the contents of a
572572// VCS repository stored locally. The zip content is written to w.
573573//
574- // repo must be an absolute path to the base of the repository, such as
575- // "/Users/some-user/my -repo".
574+ // repoRoot must be an absolute path to the base of the repository, such as
575+ // "/Users/some-user/some -repo".
576576//
577577// revision is the revision of the repository to create the zip from. Examples
578578// include HEAD or SHA sums for git repositories.
579579//
580580// subdir must be the relative path from the base of the repository, such as
581581// "sub/dir". To create a zip from the base of the repository, pass an empty
582582// string.
583- func CreateFromVCS (w io.Writer , m module.Version , repo , revision , subdir string ) (err error ) {
583+ //
584+ // If CreateFromVCS returns ErrUnrecognizedVCS, consider falling back to
585+ // CreateFromDir.
586+ func CreateFromVCS (w io.Writer , m module.Version , repoRoot , revision , subdir string ) (err error ) {
584587 defer func () {
585588 if zerr , ok := err .(* zipError ); ok {
586- zerr .path = repo
589+ zerr .path = repoRoot
587590 } else if err != nil {
588- err = & zipError {verb : "create zip from version control system" , path : repo , err : err }
591+ err = & zipError {verb : "create zip from version control system" , path : repoRoot , err : err }
589592 }
590593 }()
591594
592595 var filesToCreate []File
593596
594597 switch {
595- case isGitRepo (repo ):
596- files , err := filesInGitRepo (repo , revision , subdir )
598+ case isGitRepo (repoRoot ):
599+ files , err := filesInGitRepo (repoRoot , revision , subdir )
597600 if err != nil {
598601 return err
599602 }
600603
601604 filesToCreate = files
602605 default :
603- return fmt . Errorf ( "%q does not use a recognised version control system" , repo )
606+ return & UnrecognizedVCSError { RepoRoot : repoRoot }
604607 }
605608
606609 return Create (w , m , filesToCreate )
607610}
608611
612+ // UnrecognizedVCSError indicates that no recognized version control system was
613+ // found in the given directory.
614+ type UnrecognizedVCSError struct {
615+ RepoRoot string
616+ }
617+
618+ func (e * UnrecognizedVCSError ) Error () string {
619+ return fmt .Sprintf ("could not find a recognized version control system at %q" , e .RepoRoot )
620+ }
621+
609622// filterGitIgnored filters out any files that are git ignored in the directory.
610623func filesInGitRepo (dir , rev , subdir string ) ([]File , error ) {
611624 stderr := bytes.Buffer {}
0 commit comments