Skip to content

Clarify how multi-directory ignore patterns like "foo/bar/" shall behave #5275

Closed as not planned

Description

@ckamm

architecture.rst lists the following example:

the pattern "moo/" matches, for example, the paths "map/moo/" and "moo/"

And that works as it should.

However, which paths should a pattern that spans multiple directories match?

  • "foo/bar/" (currently matches "foo/bar/" and NOT "any/foo/bar/")
  • "*/bar/" (currently matches "any/bar/" and NOT "bar/" or "any1/any2/bar/")

And that's a bit surprising given how "moo/" does match "any/moo/". It also limits expressivity of patterns since one could always get back to the current behavior by anchoring the pattern with a starting "/".

On the other hand, there will be users who depend exactly on the current behavior of ignore patterns.

Activity

  1. added this to the 2.3.0 milestone on Oct 25, 2016
  2. ckamm commented on Oct 25, 2016

    @ckamm
    ContributorAuthor

    Current behavior in the code:

    • Patterns with a trailing slash only match directories, but otherwise behave like patterns without a slash
    • Patterns with a slash anywhere else compare against the full path
  3. ckamm commented on Oct 25, 2016

    @ckamm
    ContributorAuthor

    @guruz I've checked what changing the behavior would look like (see patch above) and am wondering whether it wouldn't be simpler to create a custom path-matching function instead of trying to write this in terms of fnmatch. Didn't you have an attempt of replacing this with regular expressions?

  4. guruz commented on Oct 26, 2016

    @guruz
    Contributor

    (WiP is here: #4999 ... )

  5. guruz commented on Nov 23, 2016

    @guruz
    Contributor

    We could agree to fix #4628 (what you reported above) by extending #4999
    But then I need to benchmark this first..

  6. self-assigned this
    on Nov 23, 2016
  7. guruz commented on Dec 14, 2016

    @guruz
    Contributor

    We benchmarked that the regexp approach is faster. (at least on OS X and Windows)

    @ckamm Do I see it correctly that your branch changes for #4999 in ckamm@d6ad54c do the full path matching?
    So we can make #4628 be fixed by your branch..

    FYI @ogoffart

  8. ckamm commented on Jan 4, 2017

    @ckamm
    ContributorAuthor

    @guruz I think it does full matching. I recommend that once we have decided to merge #4999, we fix #4628 by adding tests for that.

  9. ckamm commented on Jan 11, 2017

    @ckamm
    ContributorAuthor

    @guruz I vote for removing this ticket from 2.3. The current behavior works for users and merging #4999 is probably out of scope for 2.3. What's your opinion?

  10. ckamm commented on Jan 17, 2017

    @ckamm
    ContributorAuthor

    Here's what I propose:

    • All existing patterns that contain a / that's not at the end get migrated to be anchored, e.g. "foo/bar" -> "^/foo/bar"
    • The behavior of patterns like "moo" is unchanged (match "/moo", "/foo/moo", not "/moooo", not "/omoo")
    • The behavior of new unanchored patterns is consistent with that (even if they contain a "/"): "foo/bar" matches "/foo/bar" and "/cow/foo/bar", i.e. anything with two consecutive path components where one is "foo" and the other is "bar".

    The intention is to not change existing behavior at all, while removing the current unintuitive behavior.

    The start of an implementation of this is in #4999. @guruz

  11. reopened this on Dec 15, 2017
  12. modified the milestones: 2.3.0, 2.5.0 on Dec 15, 2017
  13. assigned and unassigned on Dec 15, 2017
  14. ckamm commented on Dec 19, 2017

    @ckamm
    ContributorAuthor

    This is now also needed to address the difference in pattern matching that existed between windows and unix platforms #6245

    Concrete migration suggestion:

    • We deploy a system-wide sync-exclude-v2.lst with master
    • When master starts and finds a user-score exclude list, it creates a v2 version based on it

    The goal is to have switching back and forth between old and new versions not be a huge pain.

    Concrete v2 exclude config file could look like this

    {
       version: 2, // new, to make future work easier
       excludes: [
           {
               pattern: "moo", 
               directory_only: true, // old trailing / 
               may_remove: true, // old ']' prefix
               match_full_path: false,  // new for this ticket, to allow 'moo/foo' patterns that match 'prefex/moo/foo'
               star_matches_slash: true // for #6245, used when migrating old windows patterns
           } // , ...
       ]
    }
    
  15. modified the milestones: 2.5.0, 2.6.0 on Apr 10, 2018
  16. modified the milestones: 2.6.0, 2.7.0 on Mar 25, 2019
  17. modified the milestones: 2.7.0, Backlog on Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions