Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
validate git hash as short
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Apr 19, 2020
commit 69e6ce72e800e2a1f595677fcc30d940e958e471
2 changes: 1 addition & 1 deletion src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const setupActions = async ({ actions, send, path }: SetupActions): Promi
const currentCommits: string[] = await git.loadCommitHistory()
for (const commit of commits) {
// validate that commit has not already been created as a safety net
if (currentCommits.includes(commit)) {
if (currentCommits.includes(git.getShortHash(commit))) {
logger(`Commit ${commit} already loaded`)
alreadyLoaded = true
continue
Expand Down
7 changes: 7 additions & 0 deletions src/services/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as TT from 'typings/tutorial'
import { exec, exists } from '../node'
import logger from '../logger'
import { stringify } from 'querystring'

const gitOrigin = 'coderoad'

Expand Down Expand Up @@ -153,3 +154,9 @@ export async function loadCommitHistory(): Promise<string[]> {
return []
}
}

// return the short form of a hash (first 7 characters)
// using `git rev-parse` seems unnecessarily slower
export function getShortHash(hash: string): string {
return hash.slice(0, 7)
}