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

Commitc8e9721

Browse files
committed
return to original branch even in failure
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent3be863b commitc8e9721

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

‎src/utils/commits.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,45 @@ export async function getCommits({
4545
thrownewError(`Code branch "${codeBranch}" not found`);
4646
}
4747

48-
console.log("branches",branches);
49-
50-
// Checkout the code branches
51-
awaitgit.checkout(codeBranch);
52-
53-
console.log("checked out");
54-
55-
// Load all logs
56-
constlogs=awaitgit.log();
57-
58-
console.log("logs",logs);
48+
// track the original branch in case of failure
49+
constoriginalBranch=branches.current;
5950

6051
// Filter relevant logs
6152
constcommits:CommitLogObject={};
6253

63-
for(constcommitoflogs.all){
64-
constmatches=commit.message.match(
65-
/^(?<stepId>(?<levelId>L\d+)(S\d+))(?<stepType>[QA])?/
66-
);
67-
68-
if(matches&&matches.length){
69-
// Use an object of commit arrays to collect all commits
70-
constposition=matches[0];
71-
if(!commits[position]){
72-
// does not exist, create the list
73-
commits[position]=[commit.hash];
74-
}else{
75-
// add to the list
76-
commits[position].push(commit.hash);
54+
try{
55+
// Checkout the code branches
56+
awaitgit.checkout(codeBranch);
57+
58+
// Load all logs
59+
constlogs=awaitgit.log();
60+
61+
for(constcommitoflogs.all){
62+
constmatches=commit.message.match(
63+
/^(?<stepId>(?<levelId>L\d+)(S\d+))(?<stepType>[QA])?/
64+
);
65+
66+
if(matches&&matches.length){
67+
// Use an object of commit arrays to collect all commits
68+
constposition=matches[0];
69+
if(!commits[position]){
70+
// does not exist, create the list
71+
commits[position]=[commit.hash];
72+
}else{
73+
// add to the list
74+
commits[position].push(commit.hash);
75+
}
7776
}
7877
}
78+
}catch(e){
79+
console.error("Error with checkout or commit matching");
80+
thrownewError(e.message);
81+
}finally{
82+
// revert back to the original branch on failure
83+
awaitgit.checkout(originalBranch);
84+
// cleanup the tmp directory
85+
awaitrmdir(tmpDir,{recursive:true});
7986
}
8087

81-
console.log("remove");
82-
// cleanup the tmp directory
83-
awaitrmdir(tmpDir,{recursive:true});
8488
returncommits;
8589
}

‎src/utils/schema/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export default {
193193
"The solution commits that can be loaded if the user gets stuck. It can also run commands and/or open files",
194194
},
195195
{
196-
required:["commits"],
196+
required:[],
197197
},
198198
],
199199
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp