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

fix basename being . when it is empty #1525

Merged
merged 2 commits into from
Dec 11, 2023
Merged

Conversation

joshuali925
Copy link
Contributor

filepath.Base("") is .. so when copying a hidden file like .gitignore to the same place, it becomes ..gitignore.~1~

this PR fixes the case when basename should be empty

Copy link
Collaborator

@joelim-work joelim-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patch, I can reproduce the issue as well.

About your changes, filepath.Base is already called a few lines above to remove the leading path components, so I don't think it is required again, and instead the following code should work:

basename := file[:len(file)-len(ext)]

Or alternatively:

basename := strings.TrimSuffix(file, ext)

@joshuali925
Copy link
Contributor Author

thanks for taking a look, updated

Copy link
Collaborator

@joelim-work joelim-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks once again for the bugfix.

@joelim-work joelim-work merged commit 31f4a4e into gokcehan:master Dec 11, 2023
4 checks passed
@gokcehan gokcehan mentioned this pull request Mar 31, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants