From d8fea7f34a5376f6055f452797a278eb24909712 Mon Sep 17 00:00:00 2001 From: Tom Kemper Date: Sun, 30 Oct 2016 15:56:51 +0100 Subject: [PATCH 1/2] Ignoring hg-errors in paths that are too long for hg to handle on windows --- lib/hg-utils.coffee | 8 ++++++-- test/long_windows_paths.coffee | 32 ++++++++++++++++++++++++++++++++ test/long_windows_paths.ps1 | 18 ++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/long_windows_paths.coffee create mode 100644 test/long_windows_paths.ps1 diff --git a/lib/hg-utils.coffee b/lib/hg-utils.coffee index 1484e86..48b8d8a 100644 --- a/lib/hg-utils.coffee +++ b/lib/hg-utils.coffee @@ -30,7 +30,8 @@ suppressHgWarnings = [ ] class Repository - + isWindows = process.platform == 'win32' + windowsMaxPathLength = 260 username: null password: null @@ -291,7 +292,10 @@ class Repository if err reject err if stderr?.length > 0 - reject stderr + if isWindows and stderr.length > windowsMaxPathLength + resolve(stdout) + else + reject new Error(stderr) resolve stdout handleHgError: (error) -> diff --git a/test/long_windows_paths.coffee b/test/long_windows_paths.coffee new file mode 100644 index 0000000..fb800e3 --- /dev/null +++ b/test/long_windows_paths.coffee @@ -0,0 +1,32 @@ +require 'coffee-script/register' +require './fakeWindow' +HgRepository = require '../lib/hg-repository' +TestRepository = require './testRepository' +assert = require('chai').assert +path = require 'path' +exec = require('child_process').execSync + +describe 'In a repository with a really long path', -> + testRepo = new TestRepository path.parse(__filename).name + repo = null + before -> + testRepo.init() + + isWindows = process.platform == 'win32' + unless isWindows + this.skip() + return + + beforeEach -> + repo = new HgRepository (testRepo.fullPath()) + + it 'should still return isPathIgnored true', -> + ignored_file = path.join testRepo.fullPath(), 'ignored_file' + repo.refreshStatus().then -> + assert.equal(repo.isPathIgnored(ignored_file), true) + + after -> + command = 'dir \'' + testRepo.fullPath() + '\\subDir*\' | rename-item -NewName a' + command = 'powershell -command "' + command + '"' + exec command + testRepo.destroy() diff --git a/test/long_windows_paths.ps1 b/test/long_windows_paths.ps1 new file mode 100644 index 0000000..d75366f --- /dev/null +++ b/test/long_windows_paths.ps1 @@ -0,0 +1,18 @@ +hg init $args[0] +set-location $args[0] + +Set-Content -Path ".hgignore" -Value @" +syntax:glob +ignored_file +"@ +hg add ".hgignore" + +new-item -type File "ignored_file" +new-item -type Directory "subdir" +new-item -type File "subdir/some_file" + +$subDir = get-item "subdir" +$path = $subDir.FullName +$path = $path.PadRight(259, "A") + +rename-item "subdir" (Split-Path $path -Leaf) From 7f6e43977e9b6df51a411a6db694c3c4215f0425 Mon Sep 17 00:00:00 2001 From: Tom Kemper Date: Sun, 30 Oct 2016 16:18:16 +0100 Subject: [PATCH 2/2] Broke the tests on linux since the skip wasnt working --- test/long_windows_paths.coffee | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/long_windows_paths.coffee b/test/long_windows_paths.coffee index fb800e3..d5d5bd0 100644 --- a/test/long_windows_paths.coffee +++ b/test/long_windows_paths.coffee @@ -6,17 +6,16 @@ assert = require('chai').assert path = require 'path' exec = require('child_process').execSync +isWindows = process.platform == 'win32' +unless isWindows + return + describe 'In a repository with a really long path', -> testRepo = new TestRepository path.parse(__filename).name repo = null before -> testRepo.init() - isWindows = process.platform == 'win32' - unless isWindows - this.skip() - return - beforeEach -> repo = new HgRepository (testRepo.fullPath())