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

Merith/fix322 #323

Merged
merged 2 commits into from
May 1, 2024
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 @@ -36,7 +36,7 @@ static GitConfig load(final Git jgit) {
return new GitConfigImpl(jgit.getRepository().getConfig());
}

private final StoredConfig storedConfig;
public final StoredConfig storedConfig;

GitConfigImpl(StoredConfig jgitConfig) {
this.storedConfig = requireNonNull(jgitConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public String getDisplayName() {
/**
* We disable commit signing on git init. https://github.com/pcal43/fastback/issues/165
*/
COMMIT_SIGNING_ENABLED("commit", null, "gpgsign");
COMMIT_SIGNING_ENABLED("commit", null, "gpgsign"),

// Allow reading the user's name and email from .gitconfig
USER_NAME("user", null, "name"),
USER_EMAIL("user", null, "email");

private final String sectionName, subSectionName, settingName;

Expand Down
15 changes: 15 additions & 0 deletions common/src/main/java/net/pcal/fastback/repo/RepoFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
package net.pcal.fastback.repo;

import net.pcal.fastback.config.GitConfig.Updater;
import net.pcal.fastback.config.GitConfigKey;
import net.pcal.fastback.logging.UserLogger;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.StoredConfig;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -58,6 +60,19 @@ public void doInit(final Path worldSaveDir, final UserLogger ulog) throws IOExce
final Updater updater = repo.getConfig().updater();
updater.set(COMMIT_SIGNING_ENABLED, false); // because some people have it set globally
updater.set(IS_NATIVE_GIT_ENABLED, true);

StoredConfig config = jgit.getRepository().getConfig();
String userName = config.getString("user", null, "name");
String userEmail = config.getString("user", null, "email");

// If they don't have name/email set (as most non-git-users won't), provide synthetic values as a convenience.
// Presumbably, most folks don't care.
if (userName == null || userName.isEmpty() || userEmail == null || userEmail.isEmpty()) {
// set from fastback world id
String worldId = WorldIdUtils.getWorldIdInfo(worldSaveDir).wid().toString();
config.setString("user", null, "name", worldId);
config.setString("user", null, "email", worldId + "@fastback");
}
updater.save();
ulog.message(raw("Backups initialized. Run '/backup local' to do your first backup. '/backup help' for more options."));
} catch (GitAPIException e) {
Expand Down
10 changes: 8 additions & 2 deletions common/src/main/java/net/pcal/fastback/utils/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public static int doExec(final String[] args, final Map<String, String> envOrigi
// Output a few values that are important for debugging; don't indiscriminately dump everything or someone's going
// to end up uploading a bunch of passwords into pastebin.
syslog().debug("PATH: " + env.get("PATH"));
syslog().debug("USER: " + env.get("USER"));
syslog().debug("HOME: " + env.get("HOME"));
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
syslog().debug("HOME: " + env.get("USERPROFILE"));
syslog().debug("USER: " + env.get("USERNAME"));
} else {
syslog().debug("HOME: " + env.get("HOME"));
syslog().debug("USER: " + env.get("USER"));
}

final List<String> errorBuffer = new ArrayList<>();
final Consumer<String> stdout = line -> {
syslog().debug("[STDOUT] " + line);
Expand Down