From fb7e3a353b0c9e224861c3f947d83c9a1507328b Mon Sep 17 00:00:00 2001 From: minh Date: Mon, 15 Jul 2024 12:17:27 +0700 Subject: [PATCH] [tmp] --- src/main/java/org/nqm/Gis.java | 25 +++++++++++-------- .../org/nqm/command/GitStatusCommand.java | 17 +++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/nqm/Gis.java b/src/main/java/org/nqm/Gis.java index 6083ee3..07e72de 100644 --- a/src/main/java/org/nqm/Gis.java +++ b/src/main/java/org/nqm/Gis.java @@ -1,7 +1,12 @@ package org.nqm; +import java.io.IOException; +import java.nio.file.Path; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.errors.NoWorkTreeException; import org.nqm.command.GisCommand; import org.nqm.command.GisVersion; +import org.nqm.command.GitStatusCommand; import org.nqm.config.GisLog; import org.nqm.utils.GisProcessUtils; import picocli.CommandLine; @@ -38,16 +43,16 @@ public static void setDryRun(boolean dryRun) { } public static void main(String... args) { - // try { - // System.out.println(GitStatusCommand.status(Path.of("/home/minh/projects/test/small-git-root-module/small-git-domain/.git"), false)); - // } catch (NoWorkTreeException | IOException | GitAPIException e) { - // e.printStackTrace(); - // } + try { + System.out.println(GitStatusCommand.status(Path.of("/home/minh/projects/test/small-git-root-module/small-git-craft/.git"), false)); + } catch (NoWorkTreeException | IOException | GitAPIException e) { + e.printStackTrace(); + } - var gis = new CommandLine(new Gis()); - gis.setExecutionExceptionHandler(GLOBAL_EXCEPTION_HANLER); - gis.execute(args.length == 0 - ? new String[] {GIT_STATUS, "--one-line"} - : args); + // var gis = new CommandLine(new Gis()); + // gis.setExecutionExceptionHandler(GLOBAL_EXCEPTION_HANLER); + // gis.execute(args.length == 0 + // ? new String[] {GIT_STATUS, "--one-line"} + // : args); } } diff --git a/src/main/java/org/nqm/command/GitStatusCommand.java b/src/main/java/org/nqm/command/GitStatusCommand.java index 640ed63..7a4e393 100644 --- a/src/main/java/org/nqm/command/GitStatusCommand.java +++ b/src/main/java/org/nqm/command/GitStatusCommand.java @@ -14,6 +14,7 @@ import static org.nqm.utils.StdOutUtils.coloringBranch; import static org.nqm.utils.StdOutUtils.coloringWord; import static org.nqm.utils.StdOutUtils.infof; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; @@ -26,11 +27,19 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.diff.DiffFormatter; +import org.eclipse.jgit.diff.RenameDetector; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.lib.BranchConfig; import org.eclipse.jgit.lib.BranchTrackingStatus; +import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommitList; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode; +import org.eclipse.jgit.treewalk.TreeWalk; import org.nqm.model.FileStatus; import org.nqm.utils.GisStringUtils; import org.nqm.utils.StdOutUtils; @@ -111,6 +120,14 @@ private static String statusFull(Repository repo, Status status, String localBra status.getConflicting().stream().forEach(computeStatus.apply(CONFLICT)); status.getUntrackedFolders().stream().forEach(computeStatus.apply(UNTRACKED_DIRS)); + var diff = new DiffFormatter(new ByteArrayOutputStream()); + var revlist = new RevWalk(repo); + + var rev0 = revlist.next().getId(); + var rev1 = revlist.next().getId(); + var diffs = diff.scan(rev0, rev1); + System.out.println("\u001B[33m diffs = '%s' \u001B[0m".formatted(diffs)); + statusByFiles.forEach((k, v) -> result.append(GisStringUtils.NEWLINE) .append(" ") .append(FileStatus.toPrint(k, v)));