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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions rtc2git.cli.extension/src/to/rtc/cli/migrate/git/GitMigrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ SortedSet<String> getExistingIgnoredFiles() {

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.

// add all untracked files
Status status = git.status().call();

Expand Down Expand Up @@ -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.

List<String> ignoreContent = JazzignoreTranslator.toGitignore(jazzIgnore);
Files.writeLines(new File(rootDir, gitignoreFile), ignoreContent, getCharset(), false);
additionalNames.add(gitignoreFile);
}
} else {
// delete case
new File(rootDir, gitignoreFile).delete();
// delete case except for root git ignore file
if (!".gitignore".equals(gitignoreFile)) {
new File(rootDir, gitignoreFile).delete();
additionalNames.add(gitignoreFile);
}
}
additionalNames.add(gitignoreFile);
}
}
// add additional modified name
Expand Down