@@ -12539,6 +12539,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1253912539Object.defineProperty(exports, "__esModule", ({ value: true }));
1254012540const github_1 = __nccwpck_require__(5438);
1254112541const child_process_1 = __nccwpck_require__(2081);
12542+ const fs_1 = __importDefault(__nccwpck_require__(7147));
12543+ const path_1 = __importDefault(__nccwpck_require__(1017));
1254212544const util_1 = __nccwpck_require__(3837);
1254312545const CONST_1 = __importDefault(__nccwpck_require__(9873));
1254412546const GithubUtils_1 = __importDefault(__nccwpck_require__(9296));
@@ -12591,20 +12593,31 @@ class Git {
1259112593 * @returns Structured diff result with line numbers and change information
1259212594 * @throws Error when git command fails (invalid refs, not a git repo, file not found, etc.)
1259312595 */
12594- static diff(fromRef, toRef, filePaths) {
12596+ static diff(fromRef, toRef, filePaths, shouldIncludeUntrackedFiles = false ) {
1259512597 // Build git diff command (with 0 context lines for easier parsing)
1259612598 let command = `git diff -U0 ${fromRef}`;
1259712599 if (toRef) {
1259812600 command += ` ${toRef}`;
1259912601 }
1260012602 if (filePaths) {
1260112603 const pathsArray = Array.isArray(filePaths) ? filePaths : [filePaths];
12602- const quotedPaths = pathsArray.map((path ) => `"${path }"`).join(' ');
12604+ const quotedPaths = pathsArray.map((filePath ) => `"${filePath }"`).join(' ');
1260312605 command += ` -- ${quotedPaths}`;
1260412606 }
1260512607 // Execute git diff with unified format - let errors bubble up
1260612608 const diffOutput = execSync(command);
12607- return Git.parseDiff(diffOutput);
12609+ const diffResult = Git.parseDiff(diffOutput);
12610+ // Include untracked files when diffing against working directory
12611+ if (!toRef && shouldIncludeUntrackedFiles) {
12612+ const untrackedFiles = Git.getUntrackedFiles(filePaths);
12613+ const untrackedFileDiffs = Git.createFileDiffsForUntrackedFiles(untrackedFiles);
12614+ // Merge untracked files into the diff result
12615+ if (untrackedFileDiffs.length > 0) {
12616+ diffResult.files.push(...untrackedFileDiffs);
12617+ diffResult.hasChanges = true;
12618+ }
12619+ }
12620+ return diffResult;
1260812621 }
1260912622 /**
1261012623 * Parse git diff output into structured format.
@@ -12892,7 +12905,7 @@ class Git {
1289212905 return false;
1289312906 }
1289412907 }
12895- static async getChangedFileNames(fromRef, toRef) {
12908+ static async getChangedFileNames(fromRef, toRef, shouldIncludeUntrackedFiles = false ) {
1289612909 if (IS_CI) {
1289712910 const { data: changedFiles } = await GithubUtils_1.default.octokit.pulls.listFiles({
1289812911 owner: CONST_1.default.GITHUB_OWNER,
@@ -12903,10 +12916,101 @@ class Git {
1290312916 return changedFiles.map((file) => file.filename);
1290412917 }
1290512918 // Get the diff output and check status
12906- const diffResult = this.diff(fromRef, toRef);
12919+ const diffResult = this.diff(fromRef, toRef, undefined, shouldIncludeUntrackedFiles );
1290712920 const files = diffResult.files.map((file) => file.filePath);
1290812921 return files;
1290912922 }
12923+ /**
12924+ * Get list of untracked files from git.
12925+ *
12926+ * @param filePaths - Optional specific file path(s) to filter by (relative to git repo root)
12927+ * @returns Array of untracked file paths
12928+ */
12929+ static getUntrackedFiles(filePaths) {
12930+ try {
12931+ // Get all untracked files
12932+ const untrackedOutput = execSync('git ls-files --others --exclude-standard', {
12933+ stdio: 'pipe',
12934+ });
12935+ if (!untrackedOutput.trim()) {
12936+ return [];
12937+ }
12938+ let untrackedFiles = untrackedOutput
12939+ .trim()
12940+ .split('\n')
12941+ .filter((file) => file.length > 0);
12942+ // Filter by filePaths if provided
12943+ if (filePaths) {
12944+ const pathsArray = Array.isArray(filePaths) ? filePaths : [filePaths];
12945+ const normalizedPaths = pathsArray.map((p) => path_1.default.normalize(p));
12946+ untrackedFiles = untrackedFiles.filter((file) => {
12947+ const normalizedFile = path_1.default.normalize(file);
12948+ return normalizedPaths.some((p) => normalizedFile === p || normalizedFile.startsWith(p + path_1.default.sep));
12949+ });
12950+ }
12951+ return untrackedFiles;
12952+ }
12953+ catch (error) {
12954+ // If command fails, return empty array (e.g., not a git repo)
12955+ return [];
12956+ }
12957+ }
12958+ /**
12959+ * Create FileDiff entries for untracked files by reading their content and treating all lines as added.
12960+ *
12961+ * @param untrackedFiles - Array of untracked file paths (relative to git repo root)
12962+ * @returns Array of FileDiff entries for untracked files
12963+ */
12964+ static createFileDiffsForUntrackedFiles(untrackedFiles) {
12965+ const fileDiffs = [];
12966+ for (const filePath of untrackedFiles) {
12967+ const absolutePath = path_1.default.join(process.cwd(), filePath);
12968+ // Check if file exists and is readable
12969+ if (!fs_1.default.existsSync(absolutePath) || !fs_1.default.statSync(absolutePath).isFile()) {
12970+ continue;
12971+ }
12972+ let fileContent;
12973+ try {
12974+ fileContent = fs_1.default.readFileSync(absolutePath, 'utf8');
12975+ }
12976+ catch (error) {
12977+ // Skip files that can't be read
12978+ continue;
12979+ }
12980+ // Split content into lines
12981+ const lines = fileContent.split('\n');
12982+ const addedLines = new Set();
12983+ // Create a single hunk with all lines as added
12984+ const diffLines = [];
12985+ for (let i = 0; i < lines.length; i++) {
12986+ const lineNumber = i + 1;
12987+ addedLines.add(lineNumber);
12988+ diffLines.push({
12989+ number: lineNumber,
12990+ type: 'added',
12991+ content: lines.at(i) ?? '',
12992+ });
12993+ }
12994+ // Create a single hunk for the entire file
12995+ const hunk = {
12996+ oldStart: 0,
12997+ oldCount: 0,
12998+ newStart: 1,
12999+ newCount: lines.length,
13000+ lines: diffLines,
13001+ };
13002+ const fileDiff = {
13003+ filePath,
13004+ diffType: 'added',
13005+ hunks: [hunk],
13006+ addedLines,
13007+ removedLines: new Set(),
13008+ modifiedLines: new Set(),
13009+ };
13010+ fileDiffs.push(fileDiff);
13011+ }
13012+ return fileDiffs;
13013+ }
1291013014}
1291113015exports["default"] = Git;
1291213016
0 commit comments