]> source.dussan.org Git - gitblit.git/commitdiff
fix: Fix broken pushes to tickets
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Wed, 7 Dec 2022 19:33:38 +0000 (20:33 +0100)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Wed, 7 Dec 2022 19:33:38 +0000 (20:33 +0100)
The update of JGit broke pushes to tickets. The ReceiveCommand now
requires all three arguments, oldId, newId and name, to be not null.
The ticket code handling pushes to tickets left name and old id as
null in certain cases. This is fixed by always providing values.

src/main/java/com/gitblit/git/PatchsetCommand.java
src/main/java/com/gitblit/git/PatchsetReceivePack.java
src/main/java/com/gitblit/models/TicketModel.java

index 21d2ac458105454e14891e3e4387149efaec49d6..829ece1de7939151a23b447c1d4c7566f8d9975d 100644 (file)
@@ -106,7 +106,7 @@ public class PatchsetCommand extends ReceiveCommand {
 
        public PatchsetCommand(String username, Patchset patchset) {
                super(patchset.isFF() ? ObjectId.fromString(patchset.parent) : ObjectId.zeroId(),
-                               ObjectId.fromString(patchset.tip), null);
+                               ObjectId.fromString(patchset.tip), getPatchsetBranch(patchset.ticketId, patchset.number));
                this.change = new Change(username);
                this.change.patchset = patchset;
        }
index 4a09139aa4b76178dd66d8c88169c8a003a0e1e8..c44c95ef74f2745c89e80010bf04e2e5b45bcbb8 100644 (file)
@@ -774,6 +774,7 @@ public class PatchsetReceivePack extends GitblitReceivePack {
 \r
                        // assign new id\r
                        long ticketId = ticketService.assignNewId(repository);\r
+                       patchset.ticketId = ticketId;\r
 \r
                        // create the patchset command\r
                        psCmd = new PatchsetCommand(user.username, patchset);\r
@@ -1102,6 +1103,7 @@ public class PatchsetReceivePack extends GitblitReceivePack {
                newPatchset.tip = tip;\r
                newPatchset.base = mergeBase;\r
                newPatchset.commits = totalCommits;\r
+               newPatchset.ticketId = ticket == null ? 0 : ticket.number;\r
 \r
                Patchset currPatchset = ticket == null ? null : ticket.getCurrentPatchset();\r
                if (currPatchset == null) {\r
@@ -1196,12 +1198,10 @@ public class PatchsetReceivePack extends GitblitReceivePack {
        }\r
 \r
        private RefUpdate updateRef(String ref, ObjectId newId, PatchsetType type) {\r
-               ObjectId ticketRefId = ObjectId.zeroId();\r
+               ObjectId ticketRefId = null;\r
                try {\r
                        ticketRefId = getRepository().resolve(ref);\r
-               } catch (Exception e) {\r
-                       // ignore\r
-               }\r
+               } catch (Exception ignored) {}\r
 \r
                try {\r
                        RefUpdate ru = getRepository().updateRef(ref,  false);\r
@@ -1217,7 +1217,7 @@ public class PatchsetReceivePack extends GitblitReceivePack {
                                break;\r
                        }\r
 \r
-                       ru.setExpectedOldObjectId(ticketRefId);\r
+                       ru.setExpectedOldObjectId((ticketRefId == null) ? ObjectId.zeroId() : ticketRefId);\r
                        ru.setNewObjectId(newId);\r
                        RefUpdate.Result result = ru.update(getRevWalk());\r
                        if (result == RefUpdate.Result.LOCK_FAILURE) {\r
@@ -1254,7 +1254,8 @@ public class PatchsetReceivePack extends GitblitReceivePack {
                                        ru.getResult(), ru.getName()));\r
                        return;\r
                }\r
-               ReceiveCommand cmd = new ReceiveCommand(ru.getOldObjectId(), ru.getNewObjectId(), ru.getName(), type);\r
+               ObjectId oldId = (ru.getOldObjectId() == null) ? ObjectId.zeroId() : ru.getOldObjectId();\r
+               ReceiveCommand cmd = new ReceiveCommand(oldId, ru.getNewObjectId(), ru.getName(), type);\r
                RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(cmd));\r
        }\r
 \r
@@ -1331,4 +1332,4 @@ public class PatchsetReceivePack extends GitblitReceivePack {
        public void sendAll() {\r
                ticketNotifier.sendAll();\r
        }\r
-}
+}\r
index 65e29dc06a18348cf9b9cbf9b7e056eaa7a6e85e..a60cdc440b662514e5d3e081aac9c03e9de64106 100644 (file)
@@ -1163,6 +1163,7 @@ public class TicketModel implements Serializable, Comparable<TicketModel> {
 
                private static final long serialVersionUID = 1L;
 
+               public long ticketId;
                public int number;
                public int rev;
                public String tip;