Skip to content

Commit 4baed92

Browse files
committed
fix: Fix broken pushes to tickets
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.
1 parent 60a0434 commit 4baed92

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/main/java/com/gitblit/git/PatchsetCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static long getTicketNumber(String ref) {
106106

107107
public PatchsetCommand(String username, Patchset patchset) {
108108
super(patchset.isFF() ? ObjectId.fromString(patchset.parent) : ObjectId.zeroId(),
109-
ObjectId.fromString(patchset.tip), null);
109+
ObjectId.fromString(patchset.tip), getPatchsetBranch(patchset.ticketId, patchset.number));
110110
this.change = new Change(username);
111111
this.change.patchset = patchset;
112112
}

src/main/java/com/gitblit/git/PatchsetReceivePack.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ private PatchsetCommand preparePatchset(ReceiveCommand cmd) {
774774

775775
// assign new id
776776
long ticketId = ticketService.assignNewId(repository);
777+
patchset.ticketId = ticketId;
777778

778779
// create the patchset command
779780
psCmd = new PatchsetCommand(user.username, patchset);
@@ -1102,6 +1103,7 @@ private Patchset newPatchset(TicketModel ticket, String mergeBase, String tip) {
11021103
newPatchset.tip = tip;
11031104
newPatchset.base = mergeBase;
11041105
newPatchset.commits = totalCommits;
1106+
newPatchset.ticketId = ticket == null ? 0 : ticket.number;
11051107

11061108
Patchset currPatchset = ticket == null ? null : ticket.getCurrentPatchset();
11071109
if (currPatchset == null) {
@@ -1196,12 +1198,10 @@ private Patchset newPatchset(TicketModel ticket, String mergeBase, String tip) {
11961198
}
11971199

11981200
private RefUpdate updateRef(String ref, ObjectId newId, PatchsetType type) {
1199-
ObjectId ticketRefId = ObjectId.zeroId();
1201+
ObjectId ticketRefId = null;
12001202
try {
12011203
ticketRefId = getRepository().resolve(ref);
1202-
} catch (Exception e) {
1203-
// ignore
1204-
}
1204+
} catch (Exception ignored) {}
12051205

12061206
try {
12071207
RefUpdate ru = getRepository().updateRef(ref, false);
@@ -1217,7 +1217,7 @@ private RefUpdate updateRef(String ref, ObjectId newId, PatchsetType type) {
12171217
break;
12181218
}
12191219

1220-
ru.setExpectedOldObjectId(ticketRefId);
1220+
ru.setExpectedOldObjectId((ticketRefId == null) ? ObjectId.zeroId() : ticketRefId);
12211221
ru.setNewObjectId(newId);
12221222
RefUpdate.Result result = ru.update(getRevWalk());
12231223
if (result == RefUpdate.Result.LOCK_FAILURE) {
@@ -1254,7 +1254,8 @@ private void updateReflog(RefUpdate ru) {
12541254
ru.getResult(), ru.getName()));
12551255
return;
12561256
}
1257-
ReceiveCommand cmd = new ReceiveCommand(ru.getOldObjectId(), ru.getNewObjectId(), ru.getName(), type);
1257+
ObjectId oldId = (ru.getOldObjectId() == null) ? ObjectId.zeroId() : ru.getOldObjectId();
1258+
ReceiveCommand cmd = new ReceiveCommand(oldId, ru.getNewObjectId(), ru.getName(), type);
12581259
RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(cmd));
12591260
}
12601261

@@ -1331,4 +1332,4 @@ public MergeStatus merge(TicketModel ticket) {
13311332
public void sendAll() {
13321333
ticketNotifier.sendAll();
13331334
}
1334-
}
1335+
}

src/main/java/com/gitblit/models/TicketModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ public static class Patchset implements Serializable, Comparable<Patchset> {
11631163

11641164
private static final long serialVersionUID = 1L;
11651165

1166+
public long ticketId;
11661167
public int number;
11671168
public int rev;
11681169
public String tip;

0 commit comments

Comments
 (0)