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

added ancestry check

parent 131b2996
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package de.uni_passau.fim.seibt.gitwrapper.repo;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.Optional;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -245,4 +246,17 @@ public class Commit extends Reference {
}
});
}
/**
* Checks if the given {@link Commit} is an ancestor of this commit.
*
* @param ancestor
* the {@link Commit} to check
* @return optionally <code>true</code>, if the given commit is in the history before this commit,
* <code>false</code>, if not and an {@link Optional#EMPTY empty optional}, if an error occurred.
*/
public Optional<Boolean> checkAncestry(Commit ancestor) {
return git.exec(repo.getDir(), " merge-base", "--is-ancestor", ancestor.getId(), id).map(execRes ->
execRes.exitCode == 0 ? Boolean.TRUE : execRes.exitCode == 1 ? Boolean.FALSE : null);
}
}
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