Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f663cc

Browse files
committed
check if commit exists through message name
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent4044c7f commit7f663cc

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

‎src/services/git/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,35 @@ export async function loadCommitHistory(): Promise<string[]> {
160160
exportfunctiongetShortHash(hash:string):string{
161161
returnhash.slice(0,7)
162162
}
163+
164+
exportasyncfunctiongetCommitMessage(hash:string):Promise<string|null>{
165+
try{
166+
// returns an list of commit hashes
167+
const{ stdout, stderr}=awaitexec({command:`git log -n 1 --pretty=format:%s${hash}`})
168+
if(stderr){
169+
returnnull
170+
}
171+
// string match on remote output
172+
returnstdout
173+
}catch(error){
174+
logger('error',error)
175+
// likely no git commit message found
176+
returnnull
177+
}
178+
}
179+
180+
exportasyncfunctioncommitsExistsByMessage(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}=awaitexec({command:`git log -g --grep='${message}'`})
185+
if(stderr){
186+
returnfalse
187+
}
188+
return!!stdout.length
189+
}catch(error){
190+
logger('error',error)
191+
// likely no commit found
192+
returnfalse
193+
}
194+
}

‎src/services/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*asTTfrom'typings/tutorial'
22
import*asgitfrom'../git'
3-
importloadCommitsfrom'./utils/loadCommits'
3+
import{loadCommits}from'./utils/commits'
44
import{loadWatchers,resetWatchers}from'./utils/watchers'
55
importopenFilesfrom'./utils/openFiles'
66
importrunCommandsfrom'./utils/runCommands'

‎src/services/hooks/utils/commits.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import*asgitfrom'../../git'
2+
3+
// avoid duplicate commits
4+
constverifyCommitUnique=async(hash:string):Promise<boolean>=>{
5+
constmessage:string|null=awaitgit.getCommitMessage(hash)
6+
if(!message){
7+
returnfalse
8+
}
9+
constexists:boolean=awaitgit.commitsExistsByMessage(message)
10+
returnexists
11+
}
12+
13+
exportconstloadCommits=async(commits:string[]=[]):Promise<void>=>{
14+
if(commits&&commits.length){
15+
// load the current list of commits for validation
16+
for(constcommitofcommits){
17+
constcommitExists=awaitverifyCommitUnique(commit)
18+
if(!commitExists){
19+
awaitgit.loadCommit(commit)
20+
}
21+
}
22+
}
23+
}

‎src/services/hooks/utils/loadCommits.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎src/services/logger/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{LOG}from'../../environment'
22

3-
exporttypeLog=string|number|object|null|undefined// eslint-disable-line
3+
exporttypeLog=any
44

55
constlogger=(...messages:Log[]):void=>{
66
if(!LOG){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp