Skip to content

Commit

Permalink
refactor: Refactored function for isSvnFolder (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias authored and JohnstonCode committed May 29, 2019
1 parent 0981045 commit 5e3631e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RepositoryState
} from "./common/types";
import { debounce } from "./decorators";
import { exists, readdir, stat } from "./fs";
import { readdir, stat } from "./fs";
import { configuration } from "./helpers/configuration";
import { RemoteRepository } from "./remoteRepository";
import { Repository } from "./repository";
Expand All @@ -29,6 +29,7 @@ import {
filterEvent,
IDisposable,
isDescendant,
isSvnFolder,
normalizePath
} from "./util";
import { matchAll } from "./util/globMatch";
Expand Down Expand Up @@ -219,34 +220,9 @@ export class Model implements IDisposable {
return;
}

let isSvnFolder = false;
const checkParent = level === 0;

try {
isSvnFolder = await exists(path + "/.svn");
} catch (error) {
// error
}

// If open only a subpath.
if (!isSvnFolder && level === 0) {
const pathParts = path.split(/[\\/]/);
while (pathParts.length > 0) {
pathParts.pop();
const topPath = pathParts.join("/") + "/.svn";

try {
isSvnFolder = await exists(topPath);
} catch (error) {
// error
}

if (isSvnFolder) {
break;
}
}
}

if (isSvnFolder) {
if (isSvnFolder(path, checkParent)) {
// Config based on folder path
const resourceConfig = workspace.getConfiguration("svn", Uri.file(path));

Expand Down
19 changes: 19 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,22 @@ export function fixPegRevision(file: string) {

return file;
}

export async function isSvnFolder(dir: string, checkParent: boolean = true): Promise<boolean> {

const result = await exists(`${dir}/.svn`);

if (result || !checkParent) {
return result;
}

const parent = path.dirname(dir);

// For windows: the `path.dirname("c:")` return `c:`
// For empty or doted dir, return "."
if (parent === dir || parent === ".") {
return false;
}

return await isSvnFolder(parent, true);
}

0 comments on commit 5e3631e

Please sign in to comment.