Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #284 - remove preflight calls to native git-lfs when native mode disabled #285

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*/
abstract class CommitUtils {

static SnapshotId doCommitSnapshot(final RepoImpl repo, final UserLogger ulog) throws IOException, ProcessException {
static SnapshotId doCommitSnapshot(final RepoImpl repo, final UserLogger ulog) throws IOException, ProcessException, GitAPIException {
PreflightUtils.doPreflight(repo);
final WorldId uuid = repo.getWorldId();
final GitConfig conf = repo.getConfig();
Expand Down
24 changes: 17 additions & 7 deletions common/src/main/java/net/pcal/fastback/repo/PreflightUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

import net.pcal.fastback.config.GitConfig;
import net.pcal.fastback.logging.SystemLogger;
import net.pcal.fastback.utils.EnvironmentUtils;
import net.pcal.fastback.utils.ProcessException;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.StoredConfig;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -50,7 +51,7 @@ abstract class PreflightUtils {
* Should be called prior to any heavy-lifting with git (e.g. committing or pushing). Ensures that
* key settings are all set correctly.
*/
static void doPreflight(RepoImpl repo) throws IOException, ProcessException {
static void doPreflight(RepoImpl repo) throws IOException, ProcessException, GitAPIException {
final SystemLogger syslog = syslog();
syslog.debug("Doing world maintenance");
final Git jgit = repo.getJGit();
Expand Down Expand Up @@ -78,12 +79,21 @@ static void doPreflight(RepoImpl repo) throws IOException, ProcessException {
/**
* Ensures that git-lfs is installed or uninstalled in the worktree as appropriate.
*/
private static void updateNativeLfsInstallation(final Repo repo) throws ProcessException {
if (EnvironmentUtils.isNativeGitInstalled()) {
final boolean isNativeEnabled = repo.getConfig().getBoolean(IS_NATIVE_GIT_ENABLED);
final String action = isNativeEnabled ? "install" : "uninstall";
final String[] cmd = {"git", "-C", repo.getWorkTree().getAbsolutePath(), "lfs", action, "--local"};
private static void updateNativeLfsInstallation(final RepoImpl repo) throws ProcessException, GitAPIException {
if (repo.getConfig().getBoolean(IS_NATIVE_GIT_ENABLED)) {
final String[] cmd = {"git", "-C", repo.getWorkTree().getAbsolutePath(), "lfs", "install", "--local"};
doExec(cmd, Collections.emptyMap(), s -> {}, s -> {});
} else {
try {
// jgit has builtin support for lfs, but it's weird not compatible with native lfs, so lets just
// try to avoid letting them use it.
StoredConfig jgitConfig = repo.getJGit().getRepository().getConfig();
jgitConfig.unsetSection("lfs", null);
jgitConfig.unsetSection("filter", "lfs");
jgitConfig.save();
} catch (Exception ohwell) {
syslog().debug(ohwell);
}
}
}
}
29 changes: 5 additions & 24 deletions common/src/main/java/net/pcal/fastback/repo/RepoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,16 @@ public void doCommitAndPush(final UserLogger ulog) {
final SnapshotId newSid;
try {
newSid = CommitUtils.doCommitSnapshot(this, ulog);
} catch(IOException ioe) {
syslog().error(ioe);
ulog.message(styledLocalized("fastback.chat.commit-failed", ERROR));
return;
} catch (ProcessException e) {
} catch (IOException | GitAPIException | ProcessException e) {
syslog().error(e);
ulog.message(styledLocalized("fastback.chat.commit-failed", ERROR));
return;
}
try {
PushUtils.doPush(newSid, this, ulog);
} catch(IOException ioe) {
} catch (IOException | ProcessException e) {
ulog.message(styledLocalized("fastback.chat.push-failed", ERROR));
syslog().error(ioe);
return;
} catch(ProcessException e) {
syslog().error(e);
ulog.message(styledLocalized("fastback.chat.push-failed", ERROR));
return;
}
ulog.message(localized("fastback.chat.backup-complete-elapsed", getDuration(start)));
Expand All @@ -127,11 +119,7 @@ public void doCommitSnapshot(final UserLogger ulog) {
final SnapshotId newSid;
try {
newSid = CommitUtils.doCommitSnapshot(this, ulog);
} catch(IOException ioe) {
ulog.message(styledLocalized("fastback.chat.commit-failed", ERROR));
syslog().error(ioe);
return;
} catch (ProcessException e) {
} catch (IOException | ProcessException | GitAPIException e) {
ulog.message(styledLocalized("fastback.chat.commit-failed", ERROR));
syslog().error(e);
return;
Expand All @@ -149,13 +137,9 @@ public void doPushSnapshot(SnapshotId sid, final UserLogger ulog) {
final long start = System.currentTimeMillis();
try {
PushUtils.doPush(sid, this, ulog);
} catch(IOException ioe) {
} catch (IOException | ProcessException e) {
ulog.message(styledLocalized("fastback.chat.commit-failed", ERROR));
syslog().error(ioe);
return;
} catch(ProcessException e) {
syslog().error(e);
ulog.message(styledLocalized("fastback.chat.push-failed", ERROR));
return;
}
ulog.message(UserMessage.localized("Successfully pushed " + sid.getShortName() + ". Time elapsed: "+getDuration(start))); // FIXME i18n
Expand All @@ -177,12 +161,9 @@ public void doGc(final UserLogger ulog) {
if (!doNativeCheck(ulog)) return;
try {
ReclamationUtils.doReclamation(this, ulog);
} catch (GitAPIException e) {
} catch (ProcessException | GitAPIException e) {
ulog.message(styledLocalized("Command failed. Check log for details.", ERROR)); // FIXME i18n
syslog().error(e);
} catch (ProcessException e) {
syslog().error(e);
ulog.message(styledLocalized("Command failed. Check log for details.", ERROR)); // FIXME i18n
}
}

Expand Down