summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2009-12-28 16:49:50 +0100
committerShawn O. Pearce <spearce@spearce.org>2009-12-28 15:58:40 -0800
commit5b13adcea97c19750ebfd5be226c48bb646708cf (patch)
treeeb37915002e89a0bff7661b7451de762cd4dd97b /org.eclipse.jgit/src
parent1ec393e744cd16956cd800c9a56fcae19e150241 (diff)
downloadjgit-5b13adcea97c19750ebfd5be226c48bb646708cf.tar.gz
jgit-5b13adcea97c19750ebfd5be226c48bb646708cf.zip
Add support for creating detached heads
An extra flag when creating a RefUpdate object allows the caller to destroy the symref and replace it with an object ref, a.k.a. detached HEAD. Change-Id: Ia88d48eab1eb4861ebfa39e3be9258c3824a19db Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java18
2 files changed, 38 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
index 67358c8084..fb6a27db30 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
@@ -137,10 +137,30 @@ class RefDatabase {
* to the base ref, as the symbolic ref could not be read.
*/
RefUpdate newUpdate(final String name) throws IOException {
+ return newUpdate(name, false);
+ }
+
+ /**
+ * Create a command to update, create or delete a ref in this repository.
+ *
+ * @param name
+ * name of the ref the caller wants to modify.
+ * @param detach
+ * true to detach the ref, i.e. replace symref with object ref
+ * @return an update command. The caller must finish populating this command
+ * and then invoke one of the update methods to actually make a
+ * change.
+ * @throws IOException
+ * a symbolic ref was passed in and could not be resolved back
+ * to the base ref, as the symbolic ref could not be read.
+ */
+ RefUpdate newUpdate(final String name, boolean detach) throws IOException {
refreshPackedRefs();
Ref r = readRefBasic(name, 0);
if (r == null)
r = new Ref(Ref.Storage.NEW, name, null);
+ else if (detach)
+ r = new Ref(Ref.Storage.NEW, name, r.getObjectId());
return new RefUpdate(this, r, fileForRef(r.getName()));
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 5b8b34fa6a..f576b057ca 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -502,6 +502,24 @@ public class Repository {
}
/**
+ * Create a command to update, create or delete a ref in this repository.
+ *
+ * @param ref
+ * name of the ref the caller wants to modify.
+ * @param detach
+ * true to create a detached head
+ * @return an update command. The caller must finish populating this command
+ * and then invoke one of the update methods to actually make a
+ * change.
+ * @throws IOException
+ * a symbolic ref was passed in and could not be resolved back
+ * to the base ref, as the symbolic ref could not be read.
+ */
+ public RefUpdate updateRef(final String ref, final boolean detach) throws IOException {
+ return refs.newUpdate(ref, detach);
+ }
+
+ /**
* Create a command to rename a ref in this repository
*
* @param fromRef