Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cache initial git --version check from onInitialize, reload value with `backup info`
  • Loading branch information
Merith-TK committed Apr 20, 2024
1 parent f3ab930 commit b554d0f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.pcal.fastback.retention.RetentionPolicy;
import net.pcal.fastback.retention.RetentionPolicyCodec;
import net.pcal.fastback.retention.RetentionPolicyType;
import net.pcal.fastback.utils.EnvironmentUtils;

import java.util.function.Function;

Expand Down Expand Up @@ -75,6 +76,8 @@ private static int info(final CommandSourceStack scs) {
try {
ulog.message(UserMessage.localized("fastback.chat.info-header"));
ulog.message(UserMessage.localized("fastback.chat.info-fastback-version", mod().getModVersion()));
gitVersion = getGitVersion();
gitLfsVersion = getGitLfsVersion();
if (!rf().isGitRepo(mod().getWorldDirectory())) {
// If they haven't yet run 'backup init', make sure they've installed native.
if (!isNativeOk(true, ulog, true)) return FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions common/src/main/java/net/pcal/fastback/mod/ModImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.pcal.fastback.logging.UserMessage;
import net.pcal.fastback.repo.Repo;
import net.pcal.fastback.repo.RepoFactory;
import net.pcal.fastback.utils.EnvironmentUtils;
import org.eclipse.jgit.transport.SshSessionFactory;

import java.io.IOException;
Expand All @@ -37,8 +38,7 @@
import static net.pcal.fastback.config.FastbackConfigKey.SHUTDOWN_ACTION;
import static net.pcal.fastback.logging.SystemLogger.syslog;
import static net.pcal.fastback.logging.UserMessage.localized;
import static net.pcal.fastback.utils.EnvironmentUtils.getGitLfsVersion;
import static net.pcal.fastback.utils.EnvironmentUtils.getGitVersion;
import static net.pcal.fastback.utils.EnvironmentUtils.*;
import static net.pcal.fastback.utils.Executor.executor;

class ModImpl implements LifecycleListener, Mod {
Expand Down Expand Up @@ -147,15 +147,15 @@ public Collection<Path> getModsBackupPaths() {
@Override
public void onInitialize() {
{
final String gitVersion = getGitVersion();
gitVersion = getGitVersion();
if (gitVersion == null) {
syslog().warn("git is not installed.");
} else {
syslog().info("git is installed: " + gitVersion);
}
}
{
final String gitLfsVersion = getGitLfsVersion();
gitLfsVersion = getGitLfsVersion();
if (gitLfsVersion == null) {
syslog().warn("git-lfs is not installed.");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

public class EnvironmentUtils {

public static String gitVersion;
public static String gitLfsVersion;

public static String getGitVersion() {
return execForVersion(new String[]{"git", "--version"});
}
Expand All @@ -57,8 +60,11 @@ public static boolean isNativeOk(final GitConfig conf, final UserLogger ulog, fi
public static boolean isNativeOk(boolean isNativeGitEnabled, UserLogger ulog, boolean verbose) {
if (isNativeGitEnabled) {
final Component notInstalled = Component.translatable("fastback.values.not-installed");
final String gitVersion = getGitVersion();
final String gitLfsVersion = getGitLfsVersion();
// if gitVersion or gitLfsVersion is null, then run the check again
if (gitVersion == null || gitLfsVersion == null) {
gitVersion = getGitVersion();
gitLfsVersion = getGitLfsVersion();
}
final boolean isNativeInstalled = (gitVersion != null && gitLfsVersion != null);
if (verbose || !isNativeInstalled) {
ulog.message(localized("fastback.chat.info-native-git-version", gitVersion != null ? gitVersion : notInstalled));
Expand Down

0 comments on commit b554d0f

Please sign in to comment.