Skip to content

The relative path resolution fails when the repository path is '/' #3

@amarshat

Description

@amarshat

go-gitignore/gitignore.go

Lines 250 to 252 in ae8ad1d

// extract the relative path of this file
_prefix := len(i._base) + 1
_rel := string(path[_prefix:])

When the Match logic tries to resolve a relative path from 2 paths (eg. basepath, fullpath), it simply tries to obtain the path after the length of the basepath in fullpath, i.e.

	_prefix := len(i._base) + 1
	_rel := string(path[_prefix:])

However, this would fail when the your basepath was /. Also, there is already a function which finds out the relative path, i.e. path.filepath.Rel, why not simply use that?

_rel, err := filepath.Rel(i._base, path)

Note: The / being the repository path is a case when I am trying to find out all the files in the file-system which satisfy a certain gitignore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions