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

Commit4641fdb

Browse files
committed
add reset script
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentb56993a commit4641fdb

File tree

2 files changed

+63
-37
lines changed

2 files changed

+63
-37
lines changed

‎src/channel/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
1818
import{showOutput}from'../services/testRunner/output'
1919
import{exec}from'../services/node'
2020
import{WORKSPACE_ROOT,TUTORIAL_URL}from'../environment'
21+
importresetfrom'../services/git/reset'
2122
importgetLastCommitHashfrom'../services/git/lastHash'
2223

2324
constreadFileAsync=promisify(readFile)
@@ -330,7 +331,7 @@ class Channel implements Channel {
330331
consthash=getLastCommitHash(position,tutorial?.levels||[])
331332

332333
// load timeline until last pass commit
333-
// TODO: run reset script
334+
reset({branch:tutorial?.config.repo.branch, hash})
334335

335336
// if tutorial.config.reset.command, run it
336337
if(tutorial?.config?.reset?.command){

‎src/services/git/reset.ts

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,74 @@
11
import*asfsfrom'fs'
2-
import{exec,exists}from'../node'
2+
import{promisify}from'util'
3+
import{exec}from'../node'
4+
5+
constremoveFile=promisify(fs.unlink)
36

47
interfaceInput{
58
hash:string
69
branch:string
710
}
811

12+
constignoreError=()=>{}
13+
914
// note: attempted to do this as a bash script
1015
// but requires the bash script has git permissions
1116
constreset=async({ branch, hash}:Input):Promise<void>=>{
12-
// TODO: capture branch
13-
constlocalBranch='master'
14-
15-
// switch to an empty branch
16-
awaitexec({
17-
command:'git checkout --orphan reset-orphan-branch',
18-
})
19-
// stash any current work
20-
awaitexec({
21-
command:'git stash',
22-
})
23-
// remove any other files
24-
awaitexec({
25-
command:'git rm -rf .',
26-
})
27-
// TODO: delete .gitignore
28-
29-
awaitexec({
30-
command:`git branch -D${localBranch}`,
31-
})
32-
awaitexec({
33-
command:`git checkout -b${localBranch}`,
34-
})
35-
36-
// load git timeline
37-
awaitexec({
38-
command:`git fetch coderoad${branch}`,
39-
})
40-
awaitexec({
41-
command:`git merge coderoad/${localBranch}`,
42-
})
43-
// reset to target commit hash
44-
awaitexec({
45-
command:`git reset --hard${hash}`,
46-
})
17+
constremote='coderoad'
18+
19+
try{
20+
// if no git init, will initialize
21+
// otherwise re-initializes git
22+
awaitexec({command:'git init'}).catch(console.log)
23+
24+
// capture current branch
25+
consthasBranch=awaitexec({command:'git branch --show-current'})
26+
constlocalBranch=hasBranch.stdout
27+
// check if coderoad remote exists
28+
consthasRemote=awaitexec({command:'git remote -v'}).catch(console.warn)
29+
if(!hasRemote||!hasRemote.stdout||!hasRemote.stdout.length){
30+
thrownewError('No remote found')
31+
}elseif(!hasRemote.stdout.match(newRegExp(remote))){
32+
thrownewError(`No "${remote}" remote found`)
33+
}
34+
35+
// switch to an empty branch
36+
awaitexec({
37+
command:'git checkout --orphan reset-orphan-branch',
38+
})
39+
// stash any current work
40+
awaitexec({
41+
command:'git stash',
42+
}).catch(ignoreError)
43+
44+
// remove any other files
45+
awaitexec({
46+
command:'git rm -rf .',
47+
}).catch(ignoreError)
48+
awaitremoveFile('.gitignore').catch(ignoreError)
49+
50+
awaitexec({
51+
command:`git branch -D${localBranch}`,
52+
})
53+
awaitexec({
54+
command:`git checkout -b${localBranch}`,
55+
})
56+
57+
// load git timeline
58+
awaitexec({
59+
command:`git fetch coderoad${branch}`,
60+
})
61+
awaitexec({
62+
command:`git merge coderoad/${branch}`,
63+
})
64+
// reset to target commit hash
65+
awaitexec({
66+
command:`git reset --hard${hash}`,
67+
})
68+
}catch(error){
69+
console.error('Error resetting')
70+
console.error(error.message)
71+
}
4772
}
4873

4974
exportdefaultreset

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp