@@ -2,7 +2,7 @@ import * as fs from "fs";
2
2
import util from "util" ;
3
3
import * as path from "path" ;
4
4
import gitP , { SimpleGit } from "simple-git/promise" ;
5
- import * as T from "../../typings/tutorial " ;
5
+ import { addToCommitOrder , validateCommitOrder } from "./commitOrder " ;
6
6
7
7
const mkdir = util . promisify ( fs . mkdir ) ;
8
8
const exists = util . promisify ( fs . exists ) ;
@@ -21,19 +21,20 @@ export async function getCommits({
21
21
} : GetCommitOptions ) : Promise < CommitLogObject > {
22
22
const git : SimpleGit = gitP ( localDir ) ;
23
23
24
+ // check that a repo is created
24
25
const isRepo = await git . checkIsRepo ( ) ;
25
-
26
26
if ( ! isRepo ) {
27
27
throw new Error ( "No git repo provided" ) ;
28
28
}
29
29
30
+ // setup .tmp directory
30
31
const tmpDir = path . join ( localDir , ".tmp" ) ;
31
-
32
32
const tmpDirExists = await exists ( tmpDir ) ;
33
33
if ( tmpDirExists ) {
34
34
await rmdir ( tmpDir , { recursive : true } ) ;
35
35
}
36
36
await mkdir ( tmpDir ) ;
37
+
37
38
const tempGit = gitP ( tmpDir ) ;
38
39
await tempGit . clone ( localDir , tmpDir ) ;
39
40
@@ -57,6 +58,7 @@ export async function getCommits({
57
58
58
59
// Load all logs
59
60
const logs = await git . log ( ) ;
61
+ const positions : string [ ] = [ ] ;
60
62
61
63
for ( const commit of logs . all ) {
62
64
const matches = commit . message . match (
@@ -73,6 +75,7 @@ export async function getCommits({
73
75
// add to the list
74
76
commits [ position ] . push ( commit . hash ) ;
75
77
}
78
+ positions . push ( position ) ;
76
79
} else {
77
80
const initMatches = commit . message . match ( / ^ I N I T / ) ;
78
81
if ( initMatches && initMatches . length ) {
@@ -83,9 +86,11 @@ export async function getCommits({
83
86
// add to the list
84
87
commits . INIT . push ( commit . hash ) ;
85
88
}
89
+ positions . push ( "INIT" ) ;
86
90
}
87
91
}
88
92
}
93
+ validateCommitOrder ( positions ) ;
89
94
} catch ( e ) {
90
95
console . error ( "Error with checkout or commit matching" ) ;
91
96
throw new Error ( e . message ) ;
0 commit comments