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

Never delete the root gitignore file #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

verhasi
Copy link

@verhasi verhasi commented Nov 22, 2018

The root git ignore file has additional default items not to be deleted even though the corresponding aka the root jazz ignore file is deleted.

The root git ignore file has additional default items not to be deleted even though the corresponding aka the root jazz ignore file is deleted.
Copy link
Member

@WtfJoke WtfJoke left a comment

Choose a reason for hiding this comment

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

Thank you @verhasi for your pull request 👍

See my comments, It looks like this change prevents deletion from any .gitignore, not just the root. Is my assumption wrong?

Would be cool if you could demonstrate your fix, by writing tests.

@@ -212,6 +212,7 @@ String getWorkItemTexts(List<WorkItem> workItems) {

private void gitCommit(PersonIdent ident, String comment) {
try {
initRootGitignore(rootDir);
Copy link
Member

Choose a reason for hiding this comment

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

Did you do this by accident? Shouldnt it have been by then already initialized through GitMigrator#init?

Copy link
Author

Choose a reason for hiding this comment

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

It is intentional. Actually, the initRootGitignore rebuilds the content of the root .gitignore file based on the defaults and the .jazzignore in the root if it exists. It is easier to handle the changes, if any, here than in handleJazzignores function. In case the .jazzignore is deleted it results in a change of the .gitignore but in handleJazzignores function, you cannot add .gitignore to toAdd list as it was called with toRestore and can return files to be added to the toRemove list only.

@@ -313,13 +314,18 @@ private void handleJazzignores(Set<String> relativeFileNames) {
String gitignoreFile = matcher.group(1).concat(".gitignore");
if (jazzIgnore.exists()) {
// change/add case
List<String> ignoreContent = JazzignoreTranslator.toGitignore(jazzIgnore);
Files.writeLines(new File(rootDir, gitignoreFile), ignoreContent, getCharset(), false);
if (!".gitignore".equals(gitignoreFile)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you extract this check into a method and extract .gitignore into a constant and replace it where its used like this as standalone string.

Copy link
Author

Choose a reason for hiding this comment

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

The relativeFileNames contains not only the name of the file but also the path starting from the sandbox root. This guarantees that only in the root of the sandbox will the relativeFilename be ".gitignore"
To extract is a good idea. I was brave to be lazy as I found the similar string usage just in initRootGitignore method as well.
I am going to create the tests as you proposed.

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