diff options
author | James Moger <james.moger@gitblit.com> | 2013-07-22 15:57:36 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-07-22 15:57:36 -0400 |
commit | 271a68b3b0ce6707130c77b5b009b3457d6b9d3b (patch) | |
tree | 1a0b547a73dd079586385fcb423267a8f9b8a22e /src/main/java/com/gitblit/utils/RefLogUtils.java | |
parent | a5ae3da334fc82c60d375b764065198ec54f2d31 (diff) | |
download | gitblit-271a68b3b0ce6707130c77b5b009b3457d6b9d3b.tar.gz gitblit-271a68b3b0ce6707130c77b5b009b3457d6b9d3b.zip |
Update Gitblit reflog on branch delete from UI if Gitblit has an existing reflog
Diffstat (limited to 'src/main/java/com/gitblit/utils/RefLogUtils.java')
-rw-r--r-- | src/main/java/com/gitblit/utils/RefLogUtils.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/utils/RefLogUtils.java b/src/main/java/com/gitblit/utils/RefLogUtils.java index 643fbc0f..dfb5f56d 100644 --- a/src/main/java/com/gitblit/utils/RefLogUtils.java +++ b/src/main/java/com/gitblit/utils/RefLogUtils.java @@ -20,6 +20,7 @@ import java.text.DateFormat; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -41,6 +42,7 @@ import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate.Result; @@ -96,6 +98,21 @@ public class RefLogUtils { } LOGGER.error(MessageFormat.format(pattern, parameters.toArray()), t); } + + /** + * Returns true if the repository has a reflog branch. + * + * @param repository + * @return true if the repository has a reflog branch + */ + public static boolean hasRefLogBranch(Repository repository) { + try { + return repository.getRef(GB_REFLOG) != null; + } catch(Exception e) { + LOGGER.error("failed to determine hasRefLogBranch", e); + } + return false; + } /** * Returns a RefModel for the reflog branch in the repository. If the @@ -156,6 +173,37 @@ public class RefLogUtils { } /** + * Logs a ref deletion. + * + * @param user + * @param repository + * @param ref + * @return true, if the update was successful + */ + public static boolean deleteRef(UserModel user, Repository repository, String ref) { + try { + Ref refObj = repository.getRef(ref); + if (refObj == null && !ref.startsWith(Constants.R_HEADS) && ref.startsWith(Constants.R_TAGS)) { + // find fully qualified ref + refObj = repository.getRef(Constants.R_HEADS + ref); + if (refObj == null) { + refObj = repository.getRef(Constants.R_TAGS + ref); + } + } + + if (refObj == null) { + return false; + } + + ReceiveCommand cmd = new ReceiveCommand(refObj.getObjectId(), ObjectId.zeroId(), refObj.getName()); + return updateRefLog(user, repository, Arrays.asList(cmd)); + } catch (Throwable t) { + error(t, repository, "Failed to commit reflog entry to {0}"); + } + return false; + } + + /** * Updates the reflog with the received commands. * * @param user |