MCPcopy Index your code
hub / github.com/coderoad/coderoad-vscode / reset

Function reset

src/services/reset/index.ts:14–69  ·  view source on GitHub ↗
({ branch, hash }: Input)

Source from the content-addressed store, hash-verified

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

Callers 1

onRunResetFunction · 0.85

Calls 3

execFunction · 0.90
removeFileFunction · 0.90
loggerFunction · 0.50

Tested by

no test coverage detected