Files
jj-command-line/helpers/gitSubRepoUtils.ts
T
2026-10-11 00:16:54 -04:00

86 lines
2.3 KiB
TypeScript

import { setTimeout } from "timers/promises"
import { bashRunAndReturnSync, bashRunAndShowLogsPromise } from "./bashUtils"
import { makeJJlogger } from "./jjLogger"
const logger = makeJJlogger({
filename: 'helpers/gitSubRepoUtils.ts'
})
export const subRepositoryClean = async (subRepoRelPath) => {
const repo = `${process.env.JJ_WORKSPACE_DIR}/${subRepoRelPath}`
logger.log(`clean repository ${repo} start`)
const command = `
cd ${repo}
git stash --include-untracked || true
git clean -f -X -e ".~envFormat" -e ".~jsonFormat" -e ".~shellFormat" || true
git clean -f -x -e ".~envFormat" -e ".~jsonFormat" -e ".~shellFormat" || true
git clean -xdf -e ".~envFormat" -e ".~jsonFormat" -e ".~shellFormat" || true
git reset --hard || true
`
const res = await bashRunAndReturnSync({
command: command
})
logger.log(res)
logger.success(`clean repository ${repo} done`)
return
}
export const subRepositoryPull = async (subRepoRelPath, branch, noLogger = false) => {
const repo = `${process.env.JJ_WORKSPACE_DIR}/${subRepoRelPath}`
if (!noLogger) {
logger.log(`pull repository ${repo} on ${branch} branch start`)
}
const command = `
cd "${repo}"
git checkout ${branch} || true
git config pull.rebase false --replace-all || true
git pull origin || true
`
const res = await bashRunAndReturnSync({
command: command
})
if (!noLogger) {
logger.log(res)
logger.success(`pull repository ${repo} on ${branch} branch done`)
}
return
}
export const subRepositoryPushChanges = async (subRepoRelPath, branch, commitMessage) => {
const repo = `${process.env.JJ_WORKSPACE_DIR}/${subRepoRelPath}`
logger.log(`push repository ${repo} on ${branch} branch "${commitMessage}" start`)
await subRepositoryPull(subRepoRelPath, branch)
await setTimeout(1000)
const command = `
cd "${repo}"
git status || true
git add . || true
git status || true
git diff --cached --color | cat || true
git commit -m "${commitMessage}" || true
git push origin || true
`
const res = await bashRunAndReturnSync({
command: command,
// noError: true
})
logger.log(res)
logger.success(`push repository ${repo} on ${branch} branch "${commitMessage}" done`)
return
}