]> source.dussan.org Git - gitblit.git/commitdiff
Correct update of HEAD symbolic reference when target is a tag.
authorPhilip L. McMahon <philip.l.mcmahon@gmail.com>
Fri, 27 Jan 2012 07:02:19 +0000 (23:02 -0800)
committerPhilip L. McMahon <philip.l.mcmahon@gmail.com>
Fri, 27 Jan 2012 07:02:19 +0000 (23:02 -0800)
Revised update results which are considered successful and improved error
messaging.

src/com/gitblit/utils/JGitUtils.java

index 0750b07853f49a58e1512fc4ff735dd420b04a39..05c0852c8d81d2a77c2570dbcb0378827add7270 100644 (file)
@@ -1190,12 +1190,28 @@ public class JGitUtils {
         */\r
        public static void setDefaultHead(Repository repository, Ref ref) {\r
                try {\r
-                       RefUpdate head = repository.updateRef(Constants.HEAD);\r
-                       RefUpdate.Result result = head.link(ref.getName());\r
-                       LOGGER.debug(MessageFormat.format("Set repository {0} default head to {1} ({2})",\r
-                                       repository.getDirectory().getAbsolutePath(), ref.getName(), result));\r
-               } catch (IOException e) {\r
-                       LOGGER.error("Failed to set default head!", e);\r
+                       boolean detach = !ref.getName().startsWith(Constants.R_HEADS); // detach if not a branch\r
+                       RefUpdate.Result result;\r
+                       RefUpdate head = repository.updateRef(Constants.HEAD, detach);\r
+                       if (detach) { // Tag\r
+                               RevCommit commit = getCommit(repository, ref.getObjectId().getName());\r
+                               head.setNewObjectId(commit.getId());\r
+                               result = head.forceUpdate();\r
+                       } else {\r
+                               result = head.link(ref.getName());\r
+                       }\r
+                       switch (result) {\r
+                       case NEW:\r
+                       case FORCED:\r
+                       case NO_CHANGE:\r
+                       case FAST_FORWARD:\r
+                               break;\r
+                       default:\r
+                               LOGGER.error(MessageFormat.format("{0} failed to set default head to {1} ({2})",\r
+                                               repository.getDirectory().getAbsolutePath(), ref.getName(), result));\r
+                       }\r
+               } catch (Throwable t) {\r
+                       error(t, repository, "{0} failed to set default head to {1}", ref.getName());\r
                }\r
        }\r
 \r