Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amarshat opened this issue Feb 26, 2019 · 1 comment
Open

Comments

@amarshat
Copy link

amarshat commented Feb 26, 2019

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.

@muesli
Copy link

muesli commented Jul 14, 2020

This is another edge case that would be fixed by #4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants