[push, lfs] Tell the pre-push hook whether the push is a dry run
This is a feature that does not exist in C git: an external pre-push hook doesn't know whether the push is run as a dry run. But for internal hooks written in Java it is entirely possible to give a hook this information. In JGit with its internal LFS implementation, this enables us to not perform LFS uploads in a dry run. This is kind of important because EGit frequently does a dry-run before doing the actual push to give the user a way to review what would be pushed before it actually happens. Doing an LFS upload of potentially huge files during a dry-run is wasteful, makes the dry run not actually a dry run, and leads to uploading the same file twice if followed by a real push. Use the information in the LfsPrePushHook to only do the initial call to the LFS server, but then skipping the actual upload if the push is a dry run. That way, a failure to contact the LFS server leads to an error in the dry run, as it should. Bug: 546567 Change-Id: I155430f27c4979d91096ba72fd95c3775dd3f28b Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
parent
30a137dfe5
commit
a171360292
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2017, Markus Duft <markus.duft@ssi-schaefer.com> and others
|
||||
* Copyright (C) 2017, 2022 Markus Duft <markus.duft@ssi-schaefer.com> and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Distribution License v. 1.0 which is available at
|
||||
|
@ -101,8 +101,10 @@ public String call() throws IOException, AbortedByHookException {
|
|||
}
|
||||
HttpConnection api = LfsConnectionFactory.getLfsConnection(
|
||||
getRepository(), METHOD_POST, OPERATION_UPLOAD);
|
||||
Map<String, LfsPointer> oid2ptr = requestBatchUpload(api, toPush);
|
||||
uploadContents(api, oid2ptr);
|
||||
if (!isDryRun()) {
|
||||
Map<String, LfsPointer> oid2ptr = requestBatchUpload(api, toPush);
|
||||
uploadContents(api, oid2ptr);
|
||||
}
|
||||
return EMPTY;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Obeo. and others
|
||||
* Copyright (C) 2015, 2022 Obeo and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Distribution License v. 1.0 which is available at
|
||||
|
@ -38,6 +38,8 @@ public class PrePushHook extends GitHook<String> {
|
|||
|
||||
private String refs;
|
||||
|
||||
private boolean dryRun;
|
||||
|
||||
/**
|
||||
* Constructor for PrePushHook
|
||||
* <p>
|
||||
|
@ -144,6 +146,27 @@ public void setRemoteLocation(String location) {
|
|||
remoteLocation = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the push is a dry run.
|
||||
*
|
||||
* @param dryRun
|
||||
* {@code true} if the push is a dry run, {@code false} otherwise
|
||||
* @since 6.2
|
||||
*/
|
||||
public void setDryRun(boolean dryRun) {
|
||||
this.dryRun = dryRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the push is a dry run.
|
||||
*
|
||||
* @return {@code true} if the push is a dry run, {@code false} otherwise
|
||||
* @since 6.2
|
||||
*/
|
||||
protected boolean isDryRun() {
|
||||
return dryRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Refs
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com> and others
|
||||
* Copyright (C) 2008, 2022 Marek Zawirski <marek.zawirski@gmail.com> and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Distribution License v. 1.0 which is available at
|
||||
|
@ -166,6 +166,7 @@ PushResult execute(ProgressMonitor monitor)
|
|||
if (prePush != null) {
|
||||
try {
|
||||
prePush.setRefs(willBeAttempted);
|
||||
prePush.setDryRun(transport.isDryRun());
|
||||
prePush.call();
|
||||
} catch (AbortedByHookException | IOException e) {
|
||||
throw new TransportException(e.getMessage(), e);
|
||||
|
|
Loading…
Reference in New Issue