From 38512f899e9bf9633554a52595da3d5af6aee81b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 3 Jun 2019 13:58:42 -0600 Subject: [PATCH 1/2] Prefix relatived paths with ./ to avoid gitignore quirk When passing the path to a file that is ignored via a pattern like `**.log`, libgit2 only recognizes the path as ignored if it starts with `./`. So we change the `relativize` method to include a leading `./` so that these kind of patterns work correctly on relativized paths. Co-Authored-By: Antonio Scandurra --- spec/fixtures/ignored-workspace/.gitignore | 1 + spec/fixtures/ignored-workspace/ignored.test | 0 spec/git-spec.js | 19 ++++++++++--------- src/git.js | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 spec/fixtures/ignored-workspace/ignored.test diff --git a/spec/fixtures/ignored-workspace/.gitignore b/spec/fixtures/ignored-workspace/.gitignore index e69de29b..21f4bd91 100644 --- a/spec/fixtures/ignored-workspace/.gitignore +++ b/spec/fixtures/ignored-workspace/.gitignore @@ -0,0 +1 @@ +**.test diff --git a/spec/fixtures/ignored-workspace/ignored.test b/spec/fixtures/ignored-workspace/ignored.test new file mode 100644 index 00000000..e69de29b diff --git a/spec/git-spec.js b/spec/git-spec.js index 2ebff2dd..4fa599f0 100644 --- a/spec/git-spec.js +++ b/spec/git-spec.js @@ -132,6 +132,7 @@ describe('git', () => { repo = git.open(ignoreRepoDir) expect(repo.isIgnored('a.txt')).toBe(true) expect(repo.isIgnored('subdir/subdir')).toBe(true) + expect(repo.isIgnored(repo.relativize(path.join(ignoreRepoDir, 'ignored.test')))).toBe(true) }) }) @@ -854,8 +855,8 @@ describe('git', () => { repo = git.open(__dirname) const workingDirectory = repo.getWorkingDirectory() - expect(repo.relativize(path.join(workingDirectory, 'a.txt'))).toBe('a.txt') - expect(repo.relativize(path.join(workingDirectory, 'a/b/c.txt'))).toBe('a/b/c.txt') + expect(repo.relativize(path.join(workingDirectory, 'a.txt'))).toBe('./a.txt') + expect(repo.relativize(path.join(workingDirectory, 'a/b/c.txt'))).toBe('./a/b/c.txt') expect(repo.relativize('a.txt')).toBe('a.txt') expect(repo.relativize('/not/in/working/dir')).toBe('/not/in/working/dir') expect(repo.relativize(null)).toBe(null) @@ -876,9 +877,9 @@ describe('git', () => { fs.symlinkSync(repoDirectory, linkDirectory) repo = git.open(linkDirectory) - expect(repo.relativize(path.join(repoDirectory, 'test1'))).toBe('test1') - expect(repo.relativize(path.join(linkDirectory, 'test2'))).toBe('test2') - expect(repo.relativize(path.join(linkDirectory, 'test2/test3'))).toBe('test2/test3') + expect(repo.relativize(path.join(repoDirectory, 'test1'))).toBe('./test1') + expect(repo.relativize(path.join(linkDirectory, 'test2'))).toBe('./test2') + expect(repo.relativize(path.join(linkDirectory, 'test2/test3'))).toBe('./test2/test3') expect(repo.relativize('test2/test3')).toBe('test2/test3') }) }) @@ -890,8 +891,8 @@ describe('git', () => { repo.caseInsensitiveFs = true const workingDirectory = repo.getWorkingDirectory() - expect(repo.relativize(path.join(workingDirectory.toUpperCase(), 'a.txt'))).toBe('a.txt') - expect(repo.relativize(path.join(workingDirectory.toUpperCase(), 'a/b/c.txt'))).toBe('a/b/c.txt') + expect(repo.relativize(path.join(workingDirectory.toUpperCase(), 'a.txt'))).toBe('./a.txt') + expect(repo.relativize(path.join(workingDirectory.toUpperCase(), 'a/b/c.txt'))).toBe('./a/b/c.txt') const linkDirectory = path.join(fs.realpathSync(temp.mkdirSync('lower-case-symlink')), 'link') wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures/master.git'), path.join(repoDirectory, '.git')) @@ -899,8 +900,8 @@ describe('git', () => { repo = git.open(linkDirectory) repo.caseInsensitiveFs = true - expect(repo.relativize(path.join(linkDirectory.toUpperCase(), 'test2'))).toBe('test2') - expect(repo.relativize(path.join(linkDirectory.toUpperCase(), 'test2/test3'))).toBe('test2/test3') + expect(repo.relativize(path.join(linkDirectory.toUpperCase(), 'test2'))).toBe('./test2') + expect(repo.relativize(path.join(linkDirectory.toUpperCase(), 'test2/test3'))).toBe('./test2/test3') }) }) diff --git a/src/git.js b/src/git.js index 217e6038..14efbe1b 100644 --- a/src/git.js +++ b/src/git.js @@ -169,7 +169,7 @@ Repository.prototype.relativize = function (path) { if (workingDirectory) { workingDirectory = workingDirectory.toLowerCase() if (lowerCasePath.startsWith(`${workingDirectory}/`)) { - return path.substring(workingDirectory.length + 1) + return './' + path.substring(workingDirectory.length + 1) } else if (lowerCasePath === workingDirectory) { return '' } @@ -178,7 +178,7 @@ Repository.prototype.relativize = function (path) { if (this.openedWorkingDirectory) { workingDirectory = this.openedWorkingDirectory.toLowerCase() if (lowerCasePath.startsWith(`${workingDirectory}/`)) { - return path.substring(workingDirectory.length + 1) + return './' + path.substring(workingDirectory.length + 1) } else if (lowerCasePath === workingDirectory) { return '' } @@ -187,7 +187,7 @@ Repository.prototype.relativize = function (path) { workingDirectory = this.getWorkingDirectory() if (workingDirectory) { if (path.startsWith(`${workingDirectory}/`)) { - return path.substring(workingDirectory.length + 1) + return './' + path.substring(workingDirectory.length + 1) } else if (path === workingDirectory) { return '' } @@ -195,7 +195,7 @@ Repository.prototype.relativize = function (path) { if (this.openedWorkingDirectory) { if (path.startsWith(`${this.openedWorkingDirectory}/`)) { - return path.substring(this.openedWorkingDirectory.length + 1) + return './' + path.substring(this.openedWorkingDirectory.length + 1) } else if (path === this.openedWorkingDirectory) { return '' } From d166d57501fff3d426c06a5a16ca02751edf2da5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 3 Jun 2019 14:13:52 -0600 Subject: [PATCH 2/2] Use Node 10 on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c4df7788..a3a131a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ notifications: on_success: never on_failure: change -node_js: node +node_js: 10 git: depth: 10