This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 07c679cb56 Issue #6174 (Improve git repo detection) (#6175)
07c679cb56 is described below
commit 07c679cb565a24cfcc7926b13f465f49bc04a8ab
Author: Matt Casters <[email protected]>
AuthorDate: Fri Dec 12 05:05:54 2025 +0100
Issue #6174 (Improve git repo detection) (#6175)
Co-authored-by: Matt Casters <[email protected]>
---
.../main/java/org/apache/hop/git/GitGuiPlugin.java | 45 ++++++++++++----------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git
a/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
b/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
index a9c21aa3b6..1b67da3f11 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
@@ -369,16 +369,7 @@ public class GitGuiPlugin
item.setSelection(currentBranch.equals(name));
// Change Branch when selecting one of the branch options
item.addListener(SWT.Selection, e -> gitCheckoutBranch(name));
-
- // if (++count == 10) break;
}
-
- // TODO: display only the last 10 used branches
- // if (count == 10) {
- // new MenuItem(menu, SWT.SEPARATOR);
- // MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
- // menuItem.setText("More...");
- // }
} catch (Exception e) {
new ErrorDialog(
shell,
@@ -665,11 +656,10 @@ public class GitGuiPlugin
public void rootChanged(String rootFolder, String rootName) {
// OK, let's see if we can determine the current git instance...
//
- try {
- FileObject gitConfig = HopVfs.getFileObject(rootFolder + "/.git/config");
- if (gitConfig.exists()) {
+ try (FileObject folder = findGitConfig(rootFolder)) {
+ if (folder != null) {
git = new UIGit();
- git.openRepo(rootFolder);
+ git.openRepo(HopVfs.getFilename(folder));
setBranchLabel(git.getBranch());
} else {
git = null;
@@ -684,6 +674,21 @@ public class GitGuiPlugin
enableButtons();
}
+ private FileObject findGitConfig(String rootFolderName)
+ throws HopFileException, FileSystemException {
+ FileObject folder = HopVfs.getFileObject(rootFolderName);
+ FileObject fileObject = folder.resolveFile(".git/config");
+ while (!fileObject.exists() && folder.getParent() != null) {
+ folder = folder.getParent();
+ fileObject = folder.resolveFile(".git/config");
+ }
+ if (fileObject.exists()) {
+ return folder;
+ } else {
+ return null;
+ }
+ }
+
/**
* Normalize absolute filename.
*
@@ -702,9 +707,9 @@ public class GitGuiPlugin
/**
* Normalize absolute filename
*
- * @param root
- * @param relativePath
- * @return
+ * @param root The root path
+ * @param relativePath The relative path
+ * @return The absolute filename
*/
private String getAbsoluteFilename(String root, String relativePath) {
String path = root + File.separator + relativePath;
@@ -775,10 +780,10 @@ public class GitGuiPlugin
/**
* If we have a git project we can take a look and see if a file is changed.
*
- * @param tree
- * @param treeItem
- * @param path
- * @param name
+ * @param tree The tree to use
+ * @param treeItem The tree item to paint
+ * @param path The file path
+ * @param name The name of the file
*/
@Override
public void filePainted(Tree tree, TreeItem treeItem, String path, String
name) {