Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Bossert2016-03-16 12:56:14 -0400
committerMatthias Sohn2016-03-22 05:56:23 -0400
commit6c77955735e23720cf8dda2a5397188f99dfed88 (patch)
tree54de5324b9b8cd59942c2d2e2f6d9b9f0832bfb4
parent036328293315dd2d1f6a8cc460c1446efd9da022 (diff)
downloadegit-6c77955735e23720cf8dda2a5397188f99dfed88.tar.gz
egit-6c77955735e23720cf8dda2a5397188f99dfed88.tar.xz
egit-6c77955735e23720cf8dda2a5397188f99dfed88.zip
Fix repository search dialog to detect .git files under selected root.
The search did not detect working tree with .git file in selected root folder. It always looked in sub-folders only and in case of .git folders it worked fine. Now it also checks the selected root folder additionally to its children. The Git private folders like .git folder itself are not traversed anymore. This prepares EGit to still properly detect git repositories when JGit change "https://git.eclipse.org/r/#/c/67873/" adds the evaluation of ".git" file with "gitdir" link to worktree and evaluates commondir. Bug: 477475 Change-Id: I9282c3431ca9946159f389168e4ad322ab42838c Signed-off-by: Andre Bossert <anb0s@anbos.de>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositorySearchDialog.java50
1 files changed, 26 insertions, 24 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositorySearchDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositorySearchDialog.java
index ddc510715..b98f48ec1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositorySearchDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositorySearchDialog.java
@@ -42,6 +42,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
@@ -401,34 +402,35 @@ public class RepositorySearchDialog extends WizardPage {
});
}
- private void findGitDirsRecursive(File root, Set<File> strings,
- IProgressMonitor monitor, boolean lookForNestedRepositories) {
+ private void findGitDirsRecursive(File root, Set<File> gitDirs,
+ IProgressMonitor monitor, int depth) {
if (!root.exists() || !root.isDirectory()) {
return;
}
- File[] children = root.listFiles();
- // simply ignore null
- if (children == null)
- return;
- for (File child : children) {
- if (monitor.isCanceled())
- return;
- if (!child.isDirectory())
- continue;
-
- File resolved = FileKey.resolve(child, FS.DETECTED);
- if (resolved != null) {
- strings.add(resolved.getAbsoluteFile());
- monitor.setTaskName(NLS.bind(
- UIText.RepositorySearchDialog_RepositoriesFound_message,
- Integer.valueOf(strings.size())));
- }
- else if (lookForNestedRepositories) {
- monitor.subTask(child.getPath());
- findGitDirsRecursive(child, strings, monitor,
- lookForNestedRepositories);
+ // check the root first
+ File resolved = FileKey.resolve(root, FS.DETECTED);
+ if (resolved != null) {
+ gitDirs.add(resolved.getAbsoluteFile());
+ monitor.setTaskName(NLS.bind(
+ UIText.RepositorySearchDialog_RepositoriesFound_message,
+ Integer.valueOf(gitDirs.size())));
+ }
+
+ // check depth and if we are not in private git folder ".git" itself
+ if ((depth != 0) && !root.equals(resolved)) {
+ File[] children = root.listFiles();
+ for (File child : children) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ // skip files and .git subfolders in root
+ if (child.isDirectory()
+ && !Constants.DOT_GIT.equals(child.getName())) {
+ monitor.subTask(child.getPath());
+ findGitDirsRecursive(child, gitDirs, monitor, depth - 1);
+ }
}
}
}
@@ -469,7 +471,7 @@ public class RepositorySearchDialog extends WizardPage {
IProgressMonitor.UNKNOWN);
try {
findGitDirsRecursive(file, directories, monitor,
- lookForNested);
+ lookForNested ? -1 : 1);
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}

Back to the top