Skip to content

Commit

Permalink
Merge pull request #1962 from codefori/feature/deployIgnore
Browse files Browse the repository at this point in the history
Added support for .deployignore
  • Loading branch information
worksofliam authored Apr 1, 2024
2 parents a7d6e69 + b930d9e commit e1763db
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/api/local/deployTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import createIgnore, { Ignore } from 'ignore';
import path, { basename } from 'path';
import vscode, { Uri, WorkspaceFolder } from 'vscode';
import { instance } from '../../instantiate';
import { LocalLanguageActions } from './LocalLanguageActions';
import { DeploymentMethod, DeploymentParameters } from '../../typings';
import { ConnectionConfiguration } from '../Configuration';
import { Tools } from '../Tools';
import { LocalLanguageActions } from './LocalLanguageActions';
import { Deployment } from './deployment';

type ServerFileChanges = {uploads: Uri[], relativeRemoteDeletes: string[]};
Expand Down Expand Up @@ -337,13 +336,18 @@ export namespace DeployTools {

export async function getDefaultIgnoreRules(workspaceFolder: vscode.WorkspaceFolder): Promise<Ignore> {
const ignoreRules = createIgnore({ ignorecase: true }).add(`.git`);
// get the .gitignore file from workspace
const gitignores = await vscode.workspace.findFiles(new vscode.RelativePattern(workspaceFolder, `.gitignore`), ``, 1);
if (gitignores.length > 0) {
// get the .deployignore file or .gitignore file from workspace with priority to .deployignore
const ignoreFile = [
...await vscode.workspace.findFiles(new vscode.RelativePattern(workspaceFolder, `.deployignore`), ``, 1),
...await vscode.workspace.findFiles(new vscode.RelativePattern(workspaceFolder, `.gitignore`), ``, 1)
].at(0);

if (ignoreFile) {
// get the content from the file
const gitignoreContent = (await vscode.workspace.fs.readFile(gitignores[0])).toString().replace(new RegExp(`\\\r`, `g`), ``);
const gitignoreContent = (await vscode.workspace.fs.readFile(ignoreFile)).toString().replace(new RegExp(`\\\r`, `g`), ``);
ignoreRules.add(gitignoreContent.split(`\n`));
ignoreRules.add('**/.gitignore');
ignoreRules.add('**/.deployignore');
}

return ignoreRules;
Expand Down
36 changes: 34 additions & 2 deletions src/testing/deployTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class File {
remotePath?: string;

constructor(readonly name: string, content?: string[]) {
if(content) {
if (content) {
this.content = content;
} else {
this.changeContent();
Expand Down Expand Up @@ -162,13 +162,45 @@ export const DeployToolsSuite: TestSuite = {
};

await CompileTools.runAction(instance, vscode.Uri.joinPath(fakeProject.localPath!, "hello.txt"), action);

const localRoot = vscode.workspace.getWorkspaceFolder(fakeProject.localPath!)?.uri;
assert.ok(localRoot, "No workspace folder");
assert.ok(existsSync(vscode.Uri.joinPath(localRoot, `random`, `random.txt`).fsPath));
assert.ok(existsSync(vscode.Uri.joinPath(localRoot, "hello.txt").fsPath));
}
},
{
name: `Test .deployignore`, test: async () => {
const workspace = vscode.workspace.workspaceFolders![0];
const getRootFile = (name: string) => vscode.Uri.joinPath(workspace.uri, name);
const prepare = async (name: string, rollback?: boolean) => {
const file = getRootFile(rollback ? `${name}_backup` : name);
if (existsSync(file.fsPath)) {
await vscode.workspace.fs.rename(file, getRootFile(rollback ? name : `${name}_backup`), { overwrite: true });
}
return file;
};

try {
const toIgnore = ["ignore1", "ignore2", "ignore3", "ignore4", ".gitignore", ".deployignore", ".notignored"];

const deployignore = await prepare(".deployignore");
vscode.workspace.fs.writeFile(deployignore, Buffer.from("**/ignore2\n**/ignore4"));
const ignoreDeploy = await DeployTools.getDefaultIgnoreRules(workspace);
assert.strictEqual(ignoreDeploy.filter(toIgnore).join(","), "ignore1,ignore3,.notignored");
await vscode.workspace.fs.delete(deployignore);

const gitignore = await prepare(".gitignore");
await vscode.workspace.fs.writeFile(gitignore, Buffer.from("**/ignore1\n**/ignore3"));
const ignoreGit = await DeployTools.getDefaultIgnoreRules(workspace);
assert.strictEqual(ignoreGit.filter(toIgnore).join(","), "ignore2,ignore4,.notignored");
}
finally {
await prepare(".gitignore", true);
await prepare(".deployignore", true);
}
}
},
],
after: async () => {
if (fakeProject.localPath && existsSync(fakeProject.localPath.fsPath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/ifsBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { BrowserItem, BrowserItemParameters, FocusOptions, IFSFile, IFS_BROWSER_
const URI_LIST_MIMETYPE = "text/uri-list";
const URI_LIST_SEPARATOR = "\r\n";
const PROTECTED_DIRS = /^(\/|\/QOpenSys|\/QSYS\.LIB|\/QDLS|\/QOPT|\/QNTC|\/QFileSvr\.400|\/bin|\/dev|\/home|\/tmp|\/usr|\/var)$/i;
const ALWAYS_SHOW_FILES = /^(\.gitignore|\.vscode)$/i;
const ALWAYS_SHOW_FILES = /^(\.gitignore|\.vscode|\.deployignore)$/i;
type DragNDropAction = "move" | "copy";
type DragNDropBehavior = DragNDropAction | "ask";
const getDragDropBehavior = () => GlobalConfiguration.get<DragNDropBehavior>(`IfsBrowser.DragAndDropDefaultBehavior`) || "ask";
Expand Down

0 comments on commit e1763db

Please sign in to comment.