File tree Expand file tree Collapse file tree 5 files changed +57
-14
lines changed Expand file tree Collapse file tree 5 files changed +57
-14
lines changed Original file line number Diff line number Diff line change @@ -160,3 +160,35 @@ export async function loadCommitHistory(): Promise<string[]> {
160160export function getShortHash ( hash : string ) : string {
161161 return hash . slice ( 0 , 7 )
162162}
163+
164+ export async function getCommitMessage ( hash : string ) : Promise < string | null > {
165+ try {
166+ // returns an list of commit hashes
167+ const { stdout, stderr } = await exec ( { command : `git log -n 1 --pretty=format:%s ${ hash } ` } )
168+ if ( stderr ) {
169+ return null
170+ }
171+ // string match on remote output
172+ return stdout
173+ } catch ( error ) {
174+ logger ( 'error' , error )
175+ // likely no git commit message found
176+ return null
177+ }
178+ }
179+
180+ export async function commitsExistsByMessage ( message : string ) : Promise < boolean > {
181+ try {
182+ // returns an list of commit hashes
183+ // note: may not work with quotes in message
184+ const { stdout, stderr } = await exec ( { command : `git log -g --grep='${ message } '` } )
185+ if ( stderr ) {
186+ return false
187+ }
188+ return ! ! stdout . length
189+ } catch ( error ) {
190+ logger ( 'error' , error )
191+ // likely no commit found
192+ return false
193+ }
194+ }
Original file line number Diff line number Diff line change 11import * as TT from 'typings/tutorial'
22import * as git from '../git'
3- import loadCommits from './utils/loadCommits '
3+ import { loadCommits } from './utils/commits '
44import { loadWatchers , resetWatchers } from './utils/watchers'
55import openFiles from './utils/openFiles'
66import runCommands from './utils/runCommands'
Original file line number Diff line number Diff line change 1+ import * as git from '../../git'
2+
3+ // avoid duplicate commits
4+ const verifyCommitUnique = async ( hash : string ) : Promise < boolean > => {
5+ const message : string | null = await git . getCommitMessage ( hash )
6+ if ( ! message ) {
7+ return false
8+ }
9+ const exists : boolean = await git . commitsExistsByMessage ( message )
10+ return exists
11+ }
12+
13+ export const loadCommits = async ( commits : string [ ] = [ ] ) : Promise < void > => {
14+ if ( commits && commits . length ) {
15+ // load the current list of commits for validation
16+ for ( const commit of commits ) {
17+ const commitExists = await verifyCommitUnique ( commit )
18+ if ( ! commitExists ) {
19+ await git . loadCommit ( commit )
20+ }
21+ }
22+ }
23+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import { LOG } from '../../environment'
22
3- export type Log = string | number | object | null | undefined // eslint-disable-line
3+ export type Log = any
44
55const logger = ( ...messages : Log [ ] ) : void => {
66 if ( ! LOG ) {
You can’t perform that action at this time.
0 commit comments