Skip to content

Commit

Permalink
Fix commit to branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Feb 9, 2024
1 parent b2d79f6 commit ede6dea
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 42 deletions.
26 changes: 16 additions & 10 deletions apps/ui/src/components/GitCommit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export default {
el.scrollIntoView();
}
});
this.isSomethingChecked = Object.keys(this.checked).length > 0;
},
open(url) {
window.open(url, '_blank');
Expand All @@ -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 = '';
});
Expand All @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions apps/ui/src/components/GitMixin.ts
Original file line number Diff line number Diff line change
@@ -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
})
});
Expand All @@ -19,16 +19,16 @@ 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: {
'Content-type': 'application/json'
},
body: JSON.stringify({
branch,
filePath,
removeFilePath,
filePaths,
removeFilePaths,
message: message
})
});
Expand Down
18 changes: 12 additions & 6 deletions apps/wgd-action-runner/steps/step_commit_branch
Original file line number Diff line number Diff line change
Expand Up @@ -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}
30 changes: 15 additions & 15 deletions src/containers/server/routes/GitController.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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(),
Expand All @@ -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(), '[email protected]');
await gitScanner.initialize();
Expand Down
11 changes: 6 additions & 5 deletions src/git/GitScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 });
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit ede6dea

Please sign in to comment.