Skip to content

Commit f6c861f

Browse files
committed
add reset script
Signed-off-by: shmck <[email protected]>
1 parent cb79854 commit f6c861f

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

Diff for: src/services/git/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as TT from 'typings/tutorial'
22
import { exec, exists } from '../node'
33
import logger from '../logger'
4-
import { stringify } from 'querystring'
54

6-
const gitOrigin = 'coderoad'
5+
export const gitOrigin = 'coderoad'
76

87
const stashAllFiles = async (): Promise<never | void> => {
98
// stash files including untracked (eg. newly created file)

Diff for: src/services/git/reset.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as fs from 'fs'
2+
import { exec, exists } from '../node'
3+
4+
interface Input {
5+
hash: string
6+
branch: string
7+
}
8+
9+
// note: attempted to do this as a bash script
10+
// but requires the bash script has git permissions
11+
const reset = async ({ branch, hash }: Input): Promise<void> => {
12+
// TODO: capture branch
13+
const localBranch = 'master'
14+
15+
// switch to an empty branch
16+
await exec({
17+
command: 'git checkout --orphan reset-orphan-branch',
18+
})
19+
// stash any current work
20+
await exec({
21+
command: 'git stash',
22+
})
23+
// remove any other files
24+
await exec({
25+
command: 'git rm -rf .',
26+
})
27+
// TODO: delete .gitignore
28+
29+
await exec({
30+
command: `git branch -D ${localBranch}`,
31+
})
32+
await exec({
33+
command: `git checkout -b ${localBranch}`,
34+
})
35+
36+
// load git timeline
37+
await exec({
38+
command: `git fetch coderoad ${branch}`,
39+
})
40+
await exec({
41+
command: `git merge coderoad/${localBranch}`,
42+
})
43+
// reset to target commit hash
44+
await exec({
45+
command: `git reset --hard ${hash}`,
46+
})
47+
}
48+
49+
export default reset

0 commit comments

Comments
 (0)