}
return f1;
}
public void performAction(ActionEvent e) {
final Git git = Git.getInstance();
File[] files = context.getRootFiles().toArray(new File[context.getRootFiles().size()]);
if (files == null || files.length == 0) {
return; // If there is a .git directory in an ancestor of any of the files in
// the context we fail.
}
for (File file : files) {
if (!file.isDirectory()) {
file = file.getParentFile();
}
if (git.getTopmostManagedParent(file) != null) {
Git.LOG.log(Level.SEVERE, "Found .git directory in ancestor of {0} ", // NOI18N
file);
return;
}
}
final Project proj = GitUtils.getProject(context);
File projFile = GitUtils.getProjectFile(proj);
if (projFile == null) {
OutputLogger logger = OutputLogger.getLogger(Git.GIT_OUTPUT_TAB_TITLE);
logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_TITLE")); // NOI18N
logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_TITLE_SEP")); // NOI18N
logger.outputInRed(
NbBundle.getMessage(InitAction.class, "MSG_CREATE_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N
logger.output(""); // NOI18N
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(InitAction.class, "MSG_CREATE_NOT_SUPPORTED_INVIEW"),// NOI18N
NbBundle.getMessage(InitAction.class, "MSG_CREATE_NOT_SUPPORTED_INVIEW_TITLE"),// NOI18N
JOptionPane.INFORMATION_MESSAGE);
logger.closeLog();
return;
}
String projName = GitProjectUtils.getProjectName(projFile);
File rootDir = getCommonAncestor(files);
final File root = getCommonAncestor(rootDir, projFile);
if (root == null) {
return;
}
final String prjName = projName;
final Repository repo = git.getRepository(root);
RequestProcessor rp = git.getRequestProcessor(root.getAbsolutePath());
GitProgressSupport supportCreate = new GitProgressSupport() {
public void perform() {
try {
OutputLogger logger = getLogger();
logger.outputInRed(
NbBundle.getMessage(InitAction.class,
"MSG_CREATE_TITLE")); // NOI18N
logger.outputInRed(
NbBundle.getMessage(InitAction.class,
"MSG_CREATE_TITLE_SEP")); // NOI18N
logger.output(
NbBundle.getMessage(InitAction.class,
"MSG_CREATE_INIT", prjName, root)); // NOI18N
repo.create();
} catch (IOException ex) {
notifyLater(ex);
}
}
};
supportCreate.start(rp, root.getAbsolutePath(),
org.openide.util.NbBundle.getMessage(InitAction.class, "MSG_Create_Progress")); // NOI18N
GitProgressSupport supportAdd = new GitProgressSupport() {
public void perform() {
OutputLogger logger = getLogger();
try {
List<File> files = getFileList(repo, root);
IndexBuilder.create(repo).
log(logger).
addAll(files).
write();
logger.output(
NbBundle.getMessage(InitAction.class,
"MSG_CREATE_ADD", files.size(), root.getAbsolutePath())); // NOI18N
logger.output(""); // NOI18N
logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_DONE_WARNING")); // NOI18N
} catch (IOException ex) {
notifyLater(ex);
} finally {
logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_DONE")); // NOI18N
logger.output(""); // NOI18N
}
}
};
supportAdd.start(rp, root.getAbsolutePath(),
org.openide.util.NbBundle.getMessage(InitAction.class, "MSG_Create_Add_Progress")); // NOI18N
GitProgressSupport supportStatus = new StatusTask(context) {
@Override
public void performAfter() {
git.versionedFilesChanged();
git.refreshAllAnnotations();
}
};
supportStatus.start(rp, root.getAbsolutePath(),