summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip L. McMahon <philip.l.mcmahon@gmail.com>2012-01-26 23:02:19 -0800
committerPhilip L. McMahon <philip.l.mcmahon@gmail.com>2012-01-26 23:02:19 -0800
commit30f9d25d77ccb5cd978d4cf8fa389ec819e90e95 (patch)
treeefeeaeebcb58d87ce51924ccba90170857ddb4d5
parent9129381d7a55c0dfae625b2b07fe1e04409df6a3 (diff)
downloadgitblit-30f9d25d77ccb5cd978d4cf8fa389ec819e90e95.tar.gz
gitblit-30f9d25d77ccb5cd978d4cf8fa389ec819e90e95.zip
Correct update of HEAD symbolic reference when target is a tag.
Revised update results which are considered successful and improved error messaging.
-rw-r--r--src/com/gitblit/utils/JGitUtils.java28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index 0750b078..05c0852c 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -1190,12 +1190,28 @@ public class JGitUtils {
*/
public static void setDefaultHead(Repository repository, Ref ref) {
try {
- RefUpdate head = repository.updateRef(Constants.HEAD);
- RefUpdate.Result result = head.link(ref.getName());
- LOGGER.debug(MessageFormat.format("Set repository {0} default head to {1} ({2})",
- repository.getDirectory().getAbsolutePath(), ref.getName(), result));
- } catch (IOException e) {
- LOGGER.error("Failed to set default head!", e);
+ boolean detach = !ref.getName().startsWith(Constants.R_HEADS); // detach if not a branch
+ RefUpdate.Result result;
+ RefUpdate head = repository.updateRef(Constants.HEAD, detach);
+ if (detach) { // Tag
+ RevCommit commit = getCommit(repository, ref.getObjectId().getName());
+ head.setNewObjectId(commit.getId());
+ result = head.forceUpdate();
+ } else {
+ result = head.link(ref.getName());
+ }
+ switch (result) {
+ case NEW:
+ case FORCED:
+ case NO_CHANGE:
+ case FAST_FORWARD:
+ break;
+ default:
+ LOGGER.error(MessageFormat.format("{0} failed to set default head to {1} ({2})",
+ repository.getDirectory().getAbsolutePath(), ref.getName(), result));
+ }
+ } catch (Throwable t) {
+ error(t, repository, "{0} failed to set default head to {1}", ref.getName());
}
}