diff --git a/common/src/main/java/net/pcal/fastback/repo/CommitUtils.java b/common/src/main/java/net/pcal/fastback/repo/CommitUtils.java index 57471bad..61270d69 100644 --- a/common/src/main/java/net/pcal/fastback/repo/CommitUtils.java +++ b/common/src/main/java/net/pcal/fastback/repo/CommitUtils.java @@ -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(); diff --git a/common/src/main/java/net/pcal/fastback/repo/PreflightUtils.java b/common/src/main/java/net/pcal/fastback/repo/PreflightUtils.java index 6c9947a7..2dff7994 100644 --- a/common/src/main/java/net/pcal/fastback/repo/PreflightUtils.java +++ b/common/src/main/java/net/pcal/fastback/repo/PreflightUtils.java @@ -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; @@ -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(); @@ -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); + } } } } diff --git a/common/src/main/java/net/pcal/fastback/repo/RepoImpl.java b/common/src/main/java/net/pcal/fastback/repo/RepoImpl.java index 0038461a..e1ea8358 100644 --- a/common/src/main/java/net/pcal/fastback/repo/RepoImpl.java +++ b/common/src/main/java/net/pcal/fastback/repo/RepoImpl.java @@ -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))); @@ -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; @@ -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 @@ -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 } }