From b85102d7044ab38f72b60e500dd6762561590fb2 Mon Sep 17 00:00:00 2001 From: Brijeshthummar02 Date: Sat, 16 May 2026 10:31:09 +0530 Subject: [PATCH] Issue #363: Include untracked files in patch generation --- .../generatepatchfile/GeneratePatchFile.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java b/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java index 12028d9a..c453f951 100644 --- a/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java +++ b/src/main/java/com/github/checkstyle/generatepatchfile/GeneratePatchFile.java @@ -73,6 +73,11 @@ public class GeneratePatchFile { */ private static final String PATCH_TXT = "patch.txt"; + /** + * GIT_ADD_INTENT_TO_ADD_COMMAND. + */ + private static final String GIT_ADD_INTENT_TO_ADD_COMMAND = "git add -N ."; + /** * Git instance. */ @@ -261,6 +266,9 @@ private void generateTwoCommitDiffPatch(RevCommit commitOld, final File destDirFile = createDestDirName(subDirName); final boolean succ = destDirFile.mkdirs(); if (succ) { + checkout(commitNew.getName()); + runShellCommand(GIT_ADD_INTENT_TO_ADD_COMMAND); + final File patchFile = new File(diffReportDirName, PATCH_TXT); final PrintStream ps = new PrintStream(new FileOutputStream(patchFile)); @@ -278,7 +286,6 @@ private void generateTwoCommitDiffPatch(RevCommit commitOld, diffFormatter.format(entries); diffFormatter.close(); - checkout(commitNew.getName()); final File reportDir = generate(); Utils.copyDir(reportDir, destDirFile); @@ -308,7 +315,8 @@ private void generateDiffPatchWithGitCommand(int headNum, String patchFormat) runShellCommand("git show > show.patch"); } else if ("diff".equals(patchFormat)) { - runShellCommand("git diff HEAD~1 HEAD > show.patch"); + runShellCommand(GIT_ADD_INTENT_TO_ADD_COMMAND); + runShellCommand("git diff HEAD~0 > show.patch"); } else if ("format".equals(patchFormat)) { runShellCommand("git format-patch -1");