Skip to content
Snippets Groups Projects
Commit b56c47f1 authored by Florian Heck's avatar Florian Heck
Browse files

add force checkout for cleanup

parent 948860fb
No related branches found
No related tags found
No related merge requests found
......@@ -78,20 +78,20 @@ public class Repository {
}
/**
* Performs a checkout of the given {@link Commit}.
* Performs a checkout of the given {@link Reference}.
*
* @param c
* the {@link Commit} to checkout
* @param ref
* the {@link Reference} to checkout
* @return whether the checkout was successful
* @see <a href=https://git-scm.com/docs/git-checkout>git checkout</a>
*/
public boolean checkout(Reference c) {
Optional<ExecRes> checkout = git.exec(dir, "checkout", c.getId());
public boolean checkout(Reference ref) {
Optional<ExecRes> checkout = git.exec(dir, "checkout", ref.getId());
Function<ExecRes, Boolean> toBoolean = res -> {
boolean failed = git.failed(res);
if (failed) {
LOG.warning(() -> String.format("Checkout of %s failed.", c));
LOG.warning(() -> String.format("Checkout of %s failed.", ref));
}
return !failed;
......@@ -100,6 +100,30 @@ public class Repository {
return checkout.map(toBoolean).orElse(false);
}
/**
* Performs a checkout of the given {@link Reference}. All changes since last commit will be discarded.
*
* @param ref
* the {@link Reference} to checkout
* @return whether the checkout was successful
* @see <a href=https://git-scm.com/docs/git-checkout>git checkout</a>
*/
public boolean forceCheckout(Reference ref) {
Optional<ExecRes> checkout = git.exec(dir, "reset", "--hard");
Function<ExecRes, Boolean> toBoolean = res -> {
boolean failed = git.failed(res);
if (failed) {
LOG.warning(() -> String.format("Reset of %s failed.", ref));
return false;
}
return checkout(ref);
};
return checkout.map(toBoolean).orElse(false);
}
/**
* Performs a fetch in this {@link Repository}.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment