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