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 7acca652bb allow creating branches from tags, fixes #7887 (#7892)
7acca652bb is described below
commit 7acca652bb10095a95fa2c8f2e0e0f6caef05d11
Author: Bart Maertens <[email protected]>
AuthorDate: Thu Aug 13 09:24:03 2026 +0200
allow creating branches from tags, fixes #7887 (#7892)
---
.../java/org/apache/hop/git/GitPerspective.java | 4 ++--
.../main/java/org/apache/hop/git/model/UIGit.java | 12 +++++++---
.../java/org/apache/hop/git/model/UIGitTest.java | 27 ++++++++++++++++++++++
3 files changed, 38 insertions(+), 5 deletions(-)
diff --git
a/plugins/misc/git/src/main/java/org/apache/hop/git/GitPerspective.java
b/plugins/misc/git/src/main/java/org/apache/hop/git/GitPerspective.java
index b84d9f7085..51de81518c 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/GitPerspective.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/GitPerspective.java
@@ -401,7 +401,7 @@ public class GitPerspective implements IHopPerspective {
MenuItem menuItem =
refMenuWidgets.findMenuItem(REF_CONTEXT_MENU_CREATE_BRANCH);
if (menuItem != null) {
- menuItem.setEnabled(isHeads || isRemotes);
+ menuItem.setEnabled(isHeads || isRemotes || isTags);
menuItem.setText(
BaseMessages.getString(PKG,
"GitPerspective.Menu.CreateBranchFrom.Text", branch));
}
@@ -1071,7 +1071,7 @@ public class GitPerspective implements IHopPerspective {
String name = dialog.open();
if (name != null) {
UIGit git = GitGuiPlugin.getInstance().getGit();
- if (git.createBranch(name)) {
+ if (git.createBranch(name, ref.getName())) {
// Refresh the explorer file, refs and commit history
refresh(true);
}
diff --git a/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
b/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
index 8c89c46f07..40a86519b3 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
@@ -1118,10 +1118,16 @@ public class UIGit extends VCS {
}
}
- public boolean createBranch(String name, String commitId) {
+ /**
+ * Create a branch that starts at the given start point and check it out.
+ *
+ * @param name the name of the new branch
+ * @param startPoint a commit id or the name of a branch, remote branch or
tag to start from.
+ * Annotated tags are peeled to the commit they point at.
+ */
+ public boolean createBranch(String name, String startPoint) {
try {
- RevCommit commit = resolve(commitId);
- git.branchCreate().setName(name).setStartPoint(commit).call();
+ git.branchCreate().setName(name).setStartPoint(startPoint).call();
checkoutBranch(getExpandedName(name, VCS.TYPE_BRANCH));
return true;
} catch (Exception e) {
diff --git
a/plugins/misc/git/src/test/java/org/apache/hop/git/model/UIGitTest.java
b/plugins/misc/git/src/test/java/org/apache/hop/git/model/UIGitTest.java
index c8ddc132e0..a4ca52ce2b 100644
--- a/plugins/misc/git/src/test/java/org/apache/hop/git/model/UIGitTest.java
+++ b/plugins/misc/git/src/test/java/org/apache/hop/git/model/UIGitTest.java
@@ -20,6 +20,7 @@ package org.apache.hop.git.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -737,6 +738,32 @@ public class UIGitTest extends RepositoryTestCase {
.orElseThrow(() -> new AssertionError("File '" + name + "' not
found"));
}
+ @Test
+ public void testCreateBranchFromTag() throws Exception {
+ RevCommit tagged = initialCommit();
+
+ uiGit.createTag("lightweight");
+ Ref annotatedTag = git.tag().setName("annotated").setMessage("Annotated
tag").call();
+
+ // Move the current branch forward, a branch created from a tag has to
start at the tagged
+ // commit and not at HEAD
+ writeTrashFile("Test2.txt", "Hello world");
+ uiGit.add("Test2.txt");
+ RevCommit head = git.commit().setMessage("second commit").call();
+ assertNotEquals(tagged.getId(), head.getId());
+
+ assertTrue(
+ uiGit.createBranch("from-lightweight",
uiGit.getExpandedName("lightweight", VCS.TYPE_TAG)));
+ assertEquals("from-lightweight", uiGit.getBranch());
+ assertEquals(tagged.getId(), db.resolve(Constants.HEAD));
+
+ // An annotated tag points at a tag object, it has to be peeled to the
commit
+ uiGit.checkout(Constants.MASTER);
+ assertTrue(uiGit.createBranch("from-annotated", annotatedTag.getName()));
+ assertEquals("from-annotated", uiGit.getBranch());
+ assertEquals(tagged.getId(), db.resolve(Constants.HEAD));
+ }
+
@Test
public void testCloneShouldFail() throws Exception {
// WhenDirAlreadyExists