@@ -2,6 +2,7 @@ import spawn from "spawndamnit";
22import path from "path" ;
33import getWorkspaces from "get-workspaces" ;
44import pkgDir from "pkg-dir" ;
5+ import { GitError } from "@changesets/errors" ;
56import { Workspace } from "@changesets/types" ;
67
78// TODO: Currently getting this working, need to decide how to
@@ -16,6 +17,8 @@ async function getProjectDirectory(cwd: string) {
1617
1718async function getMasterRef ( cwd : string ) {
1819 const gitCmd = await spawn ( "git" , [ "rev-parse" , "master" ] , { cwd } ) ;
20+ if ( gitCmd . code !== 0 )
21+ throw new GitError ( gitCmd . code , gitCmd . stderr . toString ( ) ) ;
1922 return gitCmd . stdout
2023 . toString ( )
2124 . trim ( )
@@ -82,25 +85,30 @@ async function getChangedChangesetFilesSinceMaster(
8285 cwd : string ,
8386 fullPath = false
8487) : Promise < Array < string > > {
85- const ref = await getMasterRef ( cwd ) ;
86- // First we need to find the commit where we diverged from `ref` at using `git merge-base`
87- let cmd = await spawn ( "git" , [ "merge-base" , ref , "HEAD" ] , { cwd } ) ;
88- // Now we can find which files we added
89- cmd = await spawn (
90- "git" ,
91- [ "diff" , "--name-only" , "--diff-filter=d" , "master" ] ,
92- { cwd }
93- ) ;
94-
95- let tester = / .c h a n g e s e t \/ [ ^ / ] + \. m d $ / ;
96-
97- const files = cmd . stdout
98- . toString ( )
99- . trim ( )
100- . split ( "\n" )
101- . filter ( file => tester . test ( file ) ) ;
102- if ( ! fullPath ) return files ;
103- return files . map ( file => path . resolve ( cwd , file ) ) ;
88+ try {
89+ const ref = await getMasterRef ( cwd ) ;
90+ // First we need to find the commit where we diverged from `ref` at using `git merge-base`
91+ let cmd = await spawn ( "git" , [ "merge-base" , ref , "HEAD" ] , { cwd } ) ;
92+ // Now we can find which files we added
93+ cmd = await spawn (
94+ "git" ,
95+ [ "diff" , "--name-only" , "--diff-filter=d" , "master" ] ,
96+ { cwd }
97+ ) ;
98+
99+ let tester = / .c h a n g e s e t \/ [ ^ / ] + \. m d $ / ;
100+
101+ const files = cmd . stdout
102+ . toString ( )
103+ . trim ( )
104+ . split ( "\n" )
105+ . filter ( file => tester . test ( file ) ) ;
106+ if ( ! fullPath ) return files ;
107+ return files . map ( file => path . resolve ( cwd , file ) ) ;
108+ } catch ( err ) {
109+ if ( err instanceof GitError ) return [ ] ;
110+ throw err ;
111+ }
104112}
105113
106114async function getChangedPackagesSinceCommit ( commitHash : string , cwd : string ) {
@@ -140,8 +148,13 @@ async function getChangedPackagesSinceCommit(commitHash: string, cwd: string) {
140148//
141149// Don't use this function in master branch as it returns nothing in that case.
142150async function getChangedPackagesSinceMaster ( cwd : string ) {
143- const masterRef = await getMasterRef ( cwd ) ;
144- return getChangedPackagesSinceCommit ( masterRef , cwd ) ;
151+ try {
152+ const masterRef = await getMasterRef ( cwd ) ;
153+ return getChangedPackagesSinceCommit ( masterRef , cwd ) ;
154+ } catch ( err ) {
155+ if ( err instanceof GitError ) return [ ] ;
156+ throw err ;
157+ }
145158}
146159
147160export {
0 commit comments