Git Product home page Git Product logo

Comments (7)

kaelzhang avatar kaelzhang commented on May 27, 2024 1

Thought it could be closed.

from node-ignore.

kaelzhang avatar kaelzhang commented on May 27, 2024

.gitignore exactly works in this way.

The spec says:

It is not possible to re-include a file if a parent directory of that file is excluded.

You could sightly change your ignore rules as:

.git/*
!.git/config
.ftpconfig

I thought it is solved.

from node-ignore.

icetee avatar icetee commented on May 27, 2024

No solved my problem!

I use Windows.

My rules:

.git/*
!.git/config
.ftpconfig

Accepted:

D:/ => true
D:/DEV/ => true
D:/DEV/_incubator/ => true
D:/DEV/_incubator/cubicbox/ => true
D:/DEV/_incubator/cubicbox/.ftpconfig => false [It's OK]
D:/DEV/_incubator/cubicbox/.git/ => true
D:/DEV/_incubator/cubicbox/.git/config => true
D:/DEV/_incubator/cubicbox/.git/description => true [This and other files is bad!]

from node-ignore.

kaelzhang avatar kaelzhang commented on May 27, 2024

@icetee I've added a test spec of your case, and it is ok with windows. See here for test result and here for the test case.

Could you please provide any code slices or examples?

And BTW, you should not do something like this on windows:

// WRONG!
ignore().add(rules).ignores('D:/DEV/_incubator/cubicbox/.git/description')

Because .gitignore does not works with absolute paths but only relative ones. We should use path.relative() method first, then do:

const rootOfYourProject = 'D:/DEV/_incubator/cubicbox/'
const absoluteFilePath = 'D:/DEV/_incubator/cubicbox/.git/description'

ignore().add(rules).ignores(
  // Right way
  path.relative(rootOfYourProject, absoluteFilePath)
)

from node-ignore.

icetee avatar icetee commented on May 27, 2024

@kaelzhang Can you help me?

I write spec in other test file custom.spec.js and run ./node_modules/.bin/mocha --grep deep:

var ignore = require('../');
var expect = require('chai').expect;

var ig = null;

describe('deep', function() {
  before(function() {
    ig = ignore().add([
      'abc',
      '!abc/b',
    ]);
  });

  it('#0', function() {
    expect(ig.ignores('abc')).to.equal(true); // CORRECT
  });

  it('#1', function() {
    expect(ig.ignores('abcdefg')).to.equal(false); // CORRECT
  });

  it('#2', function() {
    expect(ig.ignores('abc/b')).to.equal(false); // WRONG
  });
});

It's as if he did not notice that he was negative. Do I do something wrong?

from node-ignore.

kaelzhang avatar kaelzhang commented on May 27, 2024

The gitignore spec might help you.

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.
It is not possible to re-include a file if a parent directory of that file is excluded.

Let me explain that.

The parent directory of abc/b is abc, and abc is ignored, so abc/b could not re-include again by the rule !abc/b.

The correct way:

ignore().add([
  // The directory `abc` is not ignored, while only the things INSIDE `abc` are ignored.
  'abc/*',
  '!abc/b'
]).ignores('abc/b')  
// -> false

If abc is already ignored, we could

ignore().add([
  // If already ignores
  'abc',
  // It could be re-included itself
  '!abc',
  'abc/*',
  '!abc/b'
]).ignores('abc/b')  // -> false

from node-ignore.

icetee avatar icetee commented on May 27, 2024

I understand! Thanks for the help!

from node-ignore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.