@@ -2,7 +2,7 @@ import * as fs from "fs";
22import util from "util" ;
33import * as path from "path" ;
44import gitP , { SimpleGit } from "simple-git/promise" ;
5- import * as T from "../../typings/tutorial " ;
5+ import { addToCommitOrder , validateCommitOrder } from "./commitOrder " ;
66
77const mkdir = util . promisify ( fs . mkdir ) ;
88const exists = util . promisify ( fs . exists ) ;
@@ -21,19 +21,20 @@ export async function getCommits({
2121} : GetCommitOptions ) : Promise < CommitLogObject > {
2222 const git : SimpleGit = gitP ( localDir ) ;
2323
24+ // check that a repo is created
2425 const isRepo = await git . checkIsRepo ( ) ;
25-
2626 if ( ! isRepo ) {
2727 throw new Error ( "No git repo provided" ) ;
2828 }
2929
30+ // setup .tmp directory
3031 const tmpDir = path . join ( localDir , ".tmp" ) ;
31-
3232 const tmpDirExists = await exists ( tmpDir ) ;
3333 if ( tmpDirExists ) {
3434 await rmdir ( tmpDir , { recursive : true } ) ;
3535 }
3636 await mkdir ( tmpDir ) ;
37+
3738 const tempGit = gitP ( tmpDir ) ;
3839 await tempGit . clone ( localDir , tmpDir ) ;
3940
@@ -57,6 +58,7 @@ export async function getCommits({
5758
5859 // Load all logs
5960 const logs = await git . log ( ) ;
61+ const positions : string [ ] = [ ] ;
6062
6163 for ( const commit of logs . all ) {
6264 const matches = commit . message . match (
@@ -73,6 +75,7 @@ export async function getCommits({
7375 // add to the list
7476 commits [ position ] . push ( commit . hash ) ;
7577 }
78+ positions . push ( position ) ;
7679 } else {
7780 const initMatches = commit . message . match ( / ^ I N I T / ) ;
7881 if ( initMatches && initMatches . length ) {
@@ -83,9 +86,11 @@ export async function getCommits({
8386 // add to the list
8487 commits . INIT . push ( commit . hash ) ;
8588 }
89+ positions . push ( "INIT" ) ;
8690 }
8791 }
8892 }
93+ validateCommitOrder ( positions ) ;
8994 } catch ( e ) {
9095 console . error ( "Error with checkout or commit matching" ) ;
9196 throw new Error ( e . message ) ;
0 commit comments