Skip to content

Commit

Permalink
test: add exec debug
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Sep 22, 2023
1 parent 58ac4d6 commit 965fc8a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/ts/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import child_process from 'node:child_process'
import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs/promises'
import process from 'node:process'

import {TAnnotatedTag, TTowerOpts} from './interface'

Expand All @@ -25,12 +26,17 @@ export const exec = (cmd: string, args?: string[], opts?: any): Promise<{stdout:
})

p.on('close', (code) => {
resolve({
const result = {
cmd,
args,
code,
stdout,
stderr,
duration: Date.now() - now
})
}

resolve(result)
process.env.DEBUG && console.log(result)
})
})

Expand Down Expand Up @@ -67,8 +73,11 @@ export const clone = async (url: string, branch = 'tagtower', _cwd?: string) =>
if (remote.code === 128) {
await exec('git', ['init'], opts)
await exec('git', ['remote', 'add', 'origin', url], opts)
await exec('git', ['commit', '--allow-empty', '-m', 'init tagtower'], opts)
await setUserConfig(cwd)
await exec('git', ['commit', '--allow-empty', '-m', `init ${branch}`], opts)
await exec('git', ['push', 'origin', `HEAD:${branch}`], opts)
} else {
await setUserConfig(cwd)
}
}

Expand Down Expand Up @@ -124,3 +133,8 @@ export const deleteTag = async (opts: TTowerOpts & {tag: string}) => {
exec('git', ['tag', '--delete', opts.tag], {cwd})
])
}

const setUserConfig = async (cwd: string) => {
await exec('git', ['config', 'user.name', process.env.GIT_COMMITTER_NAME || 'Semrel Extra Bot'], {cwd})
await exec('git', ['config', 'user.email', process.env.GIT_COMMITTER_EMAIL || '[email protected]'], {cwd})
}

0 comments on commit 965fc8a

Please sign in to comment.