diff --git a/apps/ui/src/components/GitCommit.vue b/apps/ui/src/components/GitCommit.vue index 97f526bb..3f1b1cb1 100644 --- a/apps/ui/src/components/GitCommit.vue +++ b/apps/ui/src/components/GitCommit.vue @@ -198,6 +198,8 @@ export default { el.scrollIntoView(); } }); + + this.isSomethingChecked = Object.keys(this.checked).length > 0; }, open(url) { window.open(url, '_blank'); @@ -215,22 +217,26 @@ export default { } const branch = window.prompt('Enter branch name'); + if (!branch) { + alert('No branch name'); + return; + } await disableElement(event, async () => { - const filePath = []; + const filePaths = []; for (const checkedFileName of checkedFileNames) { const change = this.gitChanges.find(change => change.path === checkedFileName); if (!change?.state?.isDeleted) { - filePath.push(checkedFileName); + filePaths.push(checkedFileName); } } await this.commitBranch({ branch, message: this.commitMsg, - filePath: filePath, - removeFilePath: [] + filePaths: filePaths, + removeFilePaths: [] }); this.commitMsg = ''; }); @@ -248,23 +254,23 @@ export default { } await disableElement(event, async () => { - const filePath = []; - const removeFilePath = []; + const filePaths = []; + const removeFilePaths = []; for (const checkedFileName of checkedFileNames) { const change = this.gitChanges.find(change => change.path === checkedFileName); if (change?.state?.isDeleted) { - removeFilePath.push(checkedFileName); + removeFilePaths.push(checkedFileName); } else { - filePath.push(checkedFileName); + filePaths.push(checkedFileName); } } try { await this.commit({ message: this.commitMsg, - filePath: filePath, - removeFilePath: removeFilePath + filePaths: filePaths, + removeFilePath: removeFilePaths }); this.commitMsg = ''; } catch (err) { diff --git a/apps/ui/src/components/GitMixin.ts b/apps/ui/src/components/GitMixin.ts index 324e4785..4e7ca037 100644 --- a/apps/ui/src/components/GitMixin.ts +++ b/apps/ui/src/components/GitMixin.ts @@ -1,14 +1,14 @@ export const GitMixin = { methods: { - async commit({ message, filePath, removeFilePath }) { + async commit({ message, filePaths, removeFilePaths }) { const response = await this.authenticatedClient.fetchApi(`/api/git/${this.driveId}/commit`, { method: 'post', headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ - filePath, - removeFilePath, + filePaths, + removeFilePaths, message: message }) }); @@ -19,7 +19,7 @@ export const GitMixin = { window.location.hash = '#drive_logs'; } }, - async commitBranch({ branch, message, filePath, removeFilePath }) { + async commitBranch({ branch, message, filePaths, removeFilePaths }) { await this.authenticatedClient.fetchApi(`/api/run_action/${this.driveId}/branch`, { method: 'post', headers: { @@ -27,8 +27,8 @@ export const GitMixin = { }, body: JSON.stringify({ branch, - filePath, - removeFilePath, + filePaths, + removeFilePaths, message: message }) }); diff --git a/apps/wgd-action-runner/steps/step_commit_branch b/apps/wgd-action-runner/steps/step_commit_branch index f8a2f6b8..24b1456d 100644 --- a/apps/wgd-action-runner/steps/step_commit_branch +++ b/apps/wgd-action-runner/steps/step_commit_branch @@ -2,15 +2,21 @@ cd /repo +git reset --keep git stash clear -git stash push -git stash apply stash@{0} +COMMIT=$(git rev-parse HEAD) + +git update-index --really-refresh +git stash push --keep-index +git stash list +git stash apply stash@{0} || exit 1 -git branch -D wgd/$BRANCH +git branch -D wgd/$BRANCH || true git checkout -b wgd/$BRANCH -git commit -m "$MESSAGE" $FILES -git checkout master +git add $FILES +git commit -m "$MESSAGE" -git reset --hard +git checkout master --force +git reset --soft $COMMIT git stash apply stash@{0} diff --git a/src/containers/server/routes/GitController.ts b/src/containers/server/routes/GitController.ts index ab11d584..39b1cb10 100644 --- a/src/containers/server/routes/GitController.ts +++ b/src/containers/server/routes/GitController.ts @@ -1,14 +1,14 @@ -import {Controller, RouteGet, RouteParamBody, RouteParamPath, RouteParamUser, RoutePost, RouteUse} from './Controller'; -import {GitScanner} from '../../../git/GitScanner'; -import {UserConfigService} from '../../google_folder/UserConfigService'; -import {FileContentService} from '../../../utils/FileContentService'; -import {initJob, JobManagerContainer} from '../../job/JobManagerContainer'; -import {ContainerEngine} from '../../../ContainerEngine'; +import {Controller, RouteGet, RouteParamBody, RouteParamPath, RouteParamUser, RoutePost, RouteUse} from './Controller.ts'; +import {GitScanner} from '../../../git/GitScanner.ts'; +import {UserConfigService} from '../../google_folder/UserConfigService.ts'; +import {FileContentService} from '../../../utils/FileContentService.ts'; +import {initJob, JobManagerContainer} from '../../job/JobManagerContainer.ts'; +import {ContainerEngine} from '../../../ContainerEngine.ts'; interface CommitPost { message: string; - filePath: string[]; - removeFilePath: string[]; + filePaths: string[]; + removeFilePaths: string[]; } interface CmdPost { @@ -65,12 +65,12 @@ export default class GitController extends Controller { @RoutePost('/:driveId/commit') async postCommit(@RouteParamPath('driveId') driveId: string, @RouteParamBody() body: CommitPost, @RouteParamUser() user) { const message = body.message; - const filePaths: string[] = Array.isArray(body.filePath) - ? body.filePath - : (body.filePath ? [body.filePath] : []); - const removeFilePaths: string[] = Array.isArray(body.removeFilePath) - ? body.removeFilePath - : (body.removeFilePath ? [body.removeFilePath] : []); + const filePaths: string[] = Array.isArray(body.filePaths) + ? body.filePaths + : (body.filePaths ? [body.filePaths] : []); + const removeFilePaths: string[] = Array.isArray(body.removeFilePaths) + ? body.removeFilePaths + : (body.removeFilePaths ? [body.removeFilePaths] : []); await this.jobManagerContainer.schedule(driveId, { ...initJob(), @@ -84,7 +84,7 @@ export default class GitController extends Controller { } @RoutePost('/:driveId/cmd') - async postCmd(@RouteParamPath('driveId') driveId: string, @RouteParamBody() body: CmdPost, @RouteParamUser() user) { + async postCmd(@RouteParamPath('driveId') driveId: string, @RouteParamBody() body: CmdPost) { const transformedFileSystem = await this.filesService.getSubFileService(driveId + '_transform', ''); const gitScanner = new GitScanner(this.logger, transformedFileSystem.getRealPath(), 'wikigdrive@wikigdrive.com'); await gitScanner.initialize(); diff --git a/src/git/GitScanner.ts b/src/git/GitScanner.ts index 0eb29676..b71889f5 100644 --- a/src/git/GitScanner.ts +++ b/src/git/GitScanner.ts @@ -3,8 +3,8 @@ import path from 'path'; import {exec, spawn} from 'child_process'; import {Logger} from 'winston'; -import {UserConfig} from '../containers/google_folder/UserConfigService'; -import {TelemetryMethod} from '../telemetry'; +import {UserConfig} from '../containers/google_folder/UserConfigService.ts'; +import {TelemetryMethod} from '../telemetry.ts'; export interface GitChange { path: string; @@ -215,14 +215,14 @@ export class GitScanner { } async fetch(sshParams?: SshParams) { - await this.exec(`git fetch`, { + await this.exec('git fetch', { env: { GIT_SSH_COMMAND: sshParams?.privateKeyFile ? `ssh -i ${sanitize(sshParams.privateKeyFile)} -o StrictHostKeyChecking=no -o IdentitiesOnly=yes` : undefined } }); } - async pushToDir(dir: string, localBranch = 'master') { + async pushToDir(dir: string) { await this.exec(`git clone ${this.rootPath} ${dir}`, { skipLogger: true }); } @@ -290,6 +290,7 @@ export class GitScanner { } async resetToLocal(sshParams?: SshParams) { + await this.exec('git checkout master --force', {}); await this.exec('git reset --hard HEAD', { env: { GIT_SSH_COMMAND: sshParams?.privateKeyFile ? `ssh -i ${sanitize(sshParams.privateKeyFile)} -o StrictHostKeyChecking=no -o IdentitiesOnly=yes` : undefined @@ -634,7 +635,7 @@ export class GitScanner { const childProcess = spawn('git', ['diff', '--minimal', '--ignore-space-change'], { cwd: this.rootPath, env: {} }); - const promise = new Promise((resolve, reject) => { + const promise = new Promise((resolve) => { childProcess.on('close', resolve); });