MCPcopy Index your code
hub / github.com/cameri/nostream / runUpdate

Function runUpdate

src/cli/commands/update.ts:11–68  ·  view source on GitHub ↗
(passthrough: string[])

Source from the content-addressed store, hash-verified

9}
10
11export const runUpdate = async (passthrough: string[]): Promise<number> => {
12 const spinner = ora('Updating relay...').start()
13
14 let code = await runStop({ all: true }, [])
15 if (code !== 0) {
16 spinner.fail('Update failed while stopping relay')
17 return code
18 }
19
20 const stashResult = await runCommandWithOutput('git', ['stash', 'push', '-u', '-m', 'nostream-cli-update'])
21 if (!stashResult.ok) {
22 spinner.fail(stashResult.ok === false && stashResult.reason === 'not-found' ? 'Update failed: git is not installed' : 'Update failed while stashing local changes')
23 return 1
24 }
25 if (stashResult.code !== 0) {
26 spinner.fail('Update failed while stashing local changes')
27 return stashResult.code
28 }
29
30 const stashOutput = `${stashResult.stdout}\n${stashResult.stderr}`
31 const stashCreated = wasStashCreated(stashOutput)
32
33 code = await runCommand('git', ['pull'])
34 if (code !== 0) {
35 if (stashCreated) {
36 const restoreCode = await runCommand('git', ['stash', 'pop'])
37 if (restoreCode === 0) {
38 spinner.fail('Update failed while pulling latest changes. Restored stashed local changes.')
39 return code
40 }
41
42 spinner.fail(
43 'Update failed while pulling latest changes, and restoring stashed local changes also failed. Run `git stash list` then `git stash pop` manually.',
44 )
45 return restoreCode
46 }
47
48 spinner.fail('Update failed while pulling latest changes.')
49 return code
50 }
51
52 if (stashCreated) {
53 code = await runCommand('git', ['stash', 'pop'])
54 if (code !== 0) {
55 spinner.fail('Update pulled latest changes, but reapplying stashed changes failed')
56 return code
57 }
58 }
59
60 code = await runStart({}, passthrough)
61 if (code !== 0) {
62 spinner.fail('Update finished pull, but restart failed')
63 return code
64 }
65
66 spinner.succeed('Relay updated and restarted')
67 return 0
68}

Callers 2

update.spec.tsFile · 0.90
index.tsFile · 0.90

Calls 5

runStopFunction · 0.90
runCommandWithOutputFunction · 0.90
runCommandFunction · 0.90
runStartFunction · 0.90
wasStashCreatedFunction · 0.85

Tested by

no test coverage detected