@@ -571,41 +571,54 @@ func CreateFromDir(w io.Writer, m module.Version, dir string) (err error) {
571
571
// CreateFromVCS creates a module zip file for module m from the contents of a
572
572
// VCS repository stored locally. The zip content is written to w.
573
573
//
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".
576
576
//
577
577
// revision is the revision of the repository to create the zip from. Examples
578
578
// include HEAD or SHA sums for git repositories.
579
579
//
580
580
// subdir must be the relative path from the base of the repository, such as
581
581
// "sub/dir". To create a zip from the base of the repository, pass an empty
582
582
// 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 ) {
584
587
defer func () {
585
588
if zerr , ok := err .(* zipError ); ok {
586
- zerr .path = repo
589
+ zerr .path = repoRoot
587
590
} 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 }
589
592
}
590
593
}()
591
594
592
595
var filesToCreate []File
593
596
594
597
switch {
595
- case isGitRepo (repo ):
596
- files , err := filesInGitRepo (repo , revision , subdir )
598
+ case isGitRepo (repoRoot ):
599
+ files , err := filesInGitRepo (repoRoot , revision , subdir )
597
600
if err != nil {
598
601
return err
599
602
}
600
603
601
604
filesToCreate = files
602
605
default :
603
- return fmt . Errorf ( "%q does not use a recognised version control system" , repo )
606
+ return & UnrecognizedVCSError { RepoRoot : repoRoot }
604
607
}
605
608
606
609
return Create (w , m , filesToCreate )
607
610
}
608
611
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
+
609
622
// filterGitIgnored filters out any files that are git ignored in the directory.
610
623
func filesInGitRepo (dir , rev , subdir string ) ([]File , error ) {
611
624
stderr := bytes.Buffer {}
0 commit comments