diff --git a/src/api/local/deployTools.ts b/src/api/local/deployTools.ts index 09c2891c5..be356d536 100644 --- a/src/api/local/deployTools.ts +++ b/src/api/local/deployTools.ts @@ -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[]}; @@ -337,13 +336,18 @@ export namespace DeployTools { export async function getDefaultIgnoreRules(workspaceFolder: vscode.WorkspaceFolder): Promise { 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; diff --git a/src/testing/deployTools.ts b/src/testing/deployTools.ts index e8a0379f8..96f75c7c7 100644 --- a/src/testing/deployTools.ts +++ b/src/testing/deployTools.ts @@ -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(); @@ -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)) { diff --git a/src/views/ifsBrowser.ts b/src/views/ifsBrowser.ts index 74e7c5bd0..02245704c 100644 --- a/src/views/ifsBrowser.ts +++ b/src/views/ifsBrowser.ts @@ -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(`IfsBrowser.DragAndDropDefaultBehavior`) || "ask";