This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathgit-shell-out-strategy.js
704 lines (619 loc) · 22.1 KB
/
git-shell-out-strategy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
import path from 'path';
import os from 'os';
import {CompositeDisposable} from 'event-kit';
import {GitProcess} from 'dugite';
import {parse as parseDiff} from 'what-the-diff';
import GitPromptServer from './git-prompt-server';
import AsyncQueue from './async-queue';
import {getPackageRoot, getDugitePath, readFile, fileExists, fsStat, writeFile, isFileExecutable} from './helpers';
import GitTimingsView from './views/git-timings-view';
import WorkerManager from './worker-manager';
const LINE_ENDING_REGEX = /\r?\n/;
const GPG_HELPER_PATH = path.resolve(getPackageRoot(), 'bin', 'gpg-no-tty.sh');
export class GitError extends Error {
constructor(message) {
super(message);
this.message = message;
this.stack = new Error().stack;
}
}
/*
* Convert a Windows-style "C:\foo\bar\baz" path to a "/c/foo/bar/baz" UNIX-y
* path that the sh.exe used to execute git's credential helpers will
* understand.
*/
function toMsysPath(winPath) {
return winPath.replace(/\\/g, '/').replace(/^([^:]+):/, '/$1');
}
/*
* Apply any platform-specific munging to a path before presenting it as
* a git option.
*/
function normalizePath(inPath) {
if (process.platform === 'win32') {
return toMsysPath(inPath);
} else {
return inPath;
}
}
export default class GitShellOutStrategy {
static defaultExecArgs = {stdin: null, useGitPromptServer: false, writeOperation: false}
constructor(workingDir, options = {}) {
this.workingDir = workingDir;
if (options.queue) {
this.commandQueue = options.queue;
} else {
const parallelism = options.parallelism || Math.max(3, os.cpus().length);
this.commandQueue = new AsyncQueue({parallelism});
}
this.prompt = options.prompt || (query => Promise.reject());
this.workerManager = options.workerManager;
}
/*
* Provide an asynchronous callback to be used to request input from the user for git operations.
*
* `prompt` must be a callable that accepts a query object `{prompt, includeUsername}` and returns a Promise
* that either resolves with a result object `{[username], password}` or rejects on cancellation.
*/
setPromptCallback(prompt) {
this.prompt = prompt;
}
// Execute a command and read the output using the embedded Git environment
exec(args, {stdin, useGitPromptServer, writeOperation} = GitShellOutStrategy.defaultExecArgs) {
/* eslint-disable no-console */
const subscriptions = new CompositeDisposable();
const diagnosticsEnabled = atom.config.get('github.gitDiagnostics');
const formattedArgs = `git ${args.join(' ')} in ${this.workingDir}`;
const timingMarker = GitTimingsView.generateMarker(`git ${args.join(' ')}`);
timingMarker.mark('queued');
return this.commandQueue.push(async () => {
timingMarker.mark('prepare');
let gitPromptServer;
const env = {
GIT_TERMINAL_PROMPT: '0',
};
if (useGitPromptServer) {
gitPromptServer = new GitPromptServer();
const {
socket, electron, credentialHelper, askPass, sshWrapper,
} = await gitPromptServer.start(this.prompt);
env.ATOM_GITHUB_ASKPASS_PATH = normalizePath(askPass.script);
env.ATOM_GITHUB_CREDENTIAL_PATH = normalizePath(credentialHelper.script);
env.ATOM_GITHUB_ELECTRON_PATH = normalizePath(electron);
env.ATOM_GITHUB_SOCK_PATH = normalizePath(socket);
env.ATOM_GITHUB_WORKDIR_PATH = this.workingDir;
env.ATOM_GITHUB_DUGITE_PATH = path.join(getDugitePath(), 'git', 'bin', 'git');
// "ssh" won't respect SSH_ASKPASS unless:
// (a) it's running without a tty
// (b) DISPLAY is set to something nonempty
// But, on a Mac, DISPLAY is unset. Ensure that it is so our SSH_ASKPASS is respected.
if (!process.env.DISPLAY || process.env.DISPLAY.length === 0) {
env.DISPLAY = 'atom-github-placeholder';
}
env.ATOM_GITHUB_ORIGINAL_PATH = process.env.PATH || '';
env.ATOM_GITHUB_ORIGINAL_GIT_ASKPASS = process.env.GIT_ASKPASS || '';
env.ATOM_GITHUB_ORIGINAL_SSH_ASKPASS = process.env.SSH_ASKPASS || '';
env.ATOM_GITHUB_ORIGINAL_GIT_SSH_COMMAND = process.env.GIT_SSH_COMMAND || '';
env.SSH_ASKPASS = normalizePath(askPass.launcher);
env.GIT_ASKPASS = normalizePath(askPass.launcher);
if (process.platform === 'linux') {
env.GIT_SSH_COMMAND = sshWrapper.script;
}
args.unshift('-c', `credential.helper=${normalizePath(credentialHelper.launcher)}`);
}
if (diagnosticsEnabled) {
env.GIT_TRACE = 'true';
}
const options = {
env,
processCallback: child => {
// TODO: move callback to renderer process. send child.pid back to add cancel listener
child.on('error', err => {
console.warn('Error executing: ' + formattedArgs + ':');
console.warn(err.stack);
});
child.stdin.on('error', err => {
console.error('Error writing to process: ' + formattedArgs);
console.error(err.stack);
console.error('Tried to write: ' + stdin);
});
if (gitPromptServer) {
subscriptions.add(gitPromptServer.onDidCancel(() => {
require('tree-kill')(child.pid);
}));
}
},
};
if (stdin) {
options.stdin = stdin;
options.stdinEncoding = 'utf8';
}
if (process.env.PRINT_GIT_TIMES) {
console.time(`git:${formattedArgs}`);
}
return new Promise(async (resolve, reject) => {
const {stdout, stderr, exitCode, timing} = await this.executeGitCommand(args, options, timingMarker);
if (timing) {
const {execTime, spawnTime, ipcTime} = timing;
const now = performance.now();
timingMarker.mark('nexttick', now - execTime - spawnTime - ipcTime);
timingMarker.mark('execute', now - execTime - ipcTime);
timingMarker.mark('ipc', now - ipcTime);
}
timingMarker.finalize();
if (process.env.PRINT_GIT_TIMES) {
console.timeEnd(`git:${formattedArgs}`);
}
if (gitPromptServer) {
gitPromptServer.terminate();
}
subscriptions.dispose();
if (diagnosticsEnabled) {
const headerStyle = 'font-weight: bold; color: blue;';
console.groupCollapsed(`git:${formattedArgs}`);
console.log('%cexit status%c %d', headerStyle, 'font-weight: normal; color: black;', exitCode);
console.log('%cstdout', headerStyle);
console.log(stdout);
console.log('%cstderr', headerStyle);
console.log(stderr);
console.groupEnd();
}
if (exitCode) {
const err = new GitError(
`${formattedArgs} exited with code ${exitCode}\nstdout: ${stdout}\nstderr: ${stderr}`,
);
err.code = exitCode;
err.stdErr = stderr;
err.stdOut = stdout;
err.command = formattedArgs;
reject(err);
}
resolve(stdout);
});
}, {parallel: !writeOperation});
/* eslint-enable no-console */
}
executeGitCommand(args, options, marker = null) {
if (process.env.ATOM_GITHUB_INLINE_GIT_EXEC || !WorkerManager.getInstance().isReady()) {
marker && marker.mark('nexttick');
const promise = GitProcess.exec(args, this.workingDir, options);
marker && marker.mark('execute');
return promise;
} else {
const workerManager = this.workerManager || WorkerManager.getInstance();
return workerManager.request({
args,
workingDir: this.workingDir,
options,
});
}
}
/**
* Execute a git command that may create a commit. If the command fails because the GPG binary was invoked and unable
* to acquire a passphrase (because the pinentry program attempted to use a tty), retry with a `GitPromptServer`.
*/
gpgExec(args, options = {}) {
const gpgArgs = ['-c', `gpg.program=${GPG_HELPER_PATH}`].concat(args);
return this.exec(gpgArgs, options).catch(err => {
if (err.code === 128 && /gpg failed/.test(err.stdErr) && !options.useGitPromptServer) {
// Retry with a GitPromptServer
options.useGitPromptServer = true;
return this.exec(gpgArgs, options);
} else {
throw err;
}
});
}
async isGitRepository() {
try {
await fsStat(this.workingDir); // fails if folder doesn't exist
await this.exec(['rev-parse', '--resolve-git-dir', path.join(this.workingDir, '.git')]);
return true;
} catch (e) {
return false;
}
}
init() {
return this.exec(['init', this.workingDir]);
}
/**
* Staging/Unstaging files and patches and committing
*/
stageFiles(paths) {
if (paths.length === 0) { return Promise.resolve(null); }
const args = ['add'].concat(paths);
return this.exec(args, {writeOperation: true});
}
unstageFiles(paths, commit = 'HEAD') {
if (paths.length === 0) { return Promise.resolve(null); }
const args = ['reset', commit, '--'].concat(paths);
return this.exec(args, {writeOperation: true});
}
applyPatch(patch, {index} = {}) {
const args = ['apply', '-'];
if (index) { args.splice(1, 0, '--cached'); }
return this.exec(args, {stdin: patch, writeOperation: true});
}
commit(message, {allowEmpty, amend} = {}) {
const args = ['commit', '-m', message];
if (amend) { args.push('--amend'); }
if (allowEmpty) { args.push('--allow-empty'); }
return this.gpgExec(args, {writeOperation: true});
}
/**
* File Status and Diffs
*/
async getStatusesForChangedFiles() {
const output = await this.exec(['status', '--untracked-files=all', '-z'], {writeOperation: true});
const statusMap = {
'A': 'added',
'C': 'added', // technically copied, but we'll treat as added
'M': 'modified',
'D': 'deleted',
'U': 'modified',
'?': 'added',
};
const stagedFiles = {};
const unstagedFiles = {};
const mergeConflictFiles = {};
let statusToHead;
if (output) {
const lines = output.split('\0');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line === '') { continue; }
const [_, x, y, filePath] = line.match(/(.)(.)\s(.*)/); // eslint-disable-line no-unused-vars
if (x === 'U' || y === 'U' || (x === 'A' && y === 'A')) {
// Skipping this check here because we only run a single `await`
// and we only run it in the main, synchronous body of the for loop.
// eslint-disable-next-line no-await-in-loop
if (!statusToHead) { statusToHead = await this.diffFileStatus({target: 'HEAD'}); }
mergeConflictFiles[filePath] = {
ours: statusMap[x],
theirs: statusMap[y],
file: statusToHead[filePath] || 'equivalent',
};
continue;
}
if (x === 'R') {
stagedFiles[filePath] = 'added';
stagedFiles[lines[++i]] = 'deleted';
continue;
}
if (y !== ' ') {
unstagedFiles[filePath] = statusMap[y];
}
if (x !== ' ' && x !== '?') {
stagedFiles[filePath] = statusMap[x];
}
if (x === 'C') {
// skip the next line, which is the copied file
i++;
}
}
}
return {stagedFiles, unstagedFiles, mergeConflictFiles};
}
async diffFileStatus(options = {}) {
const args = ['diff', '--name-status', '--no-renames'];
if (options.staged) { args.push('--staged'); }
if (options.target) { args.push(options.target); }
const output = await this.exec(args);
const statusMap = {
A: 'added',
M: 'modified',
D: 'deleted',
U: 'unmerged',
};
const fileStatuses = {};
output && output.trim().split(LINE_ENDING_REGEX).forEach(line => {
const [status, filePath] = line.split('\t');
fileStatuses[filePath] = statusMap[status];
});
if (!options.staged) {
const untracked = await this.getUntrackedFiles();
untracked.forEach(filePath => { fileStatuses[filePath] = 'added'; });
}
return fileStatuses;
}
async getUntrackedFiles() {
const output = await this.exec(['ls-files', '--others', '--exclude-standard']);
if (output.trim() === '') { return []; }
return output.trim().split(LINE_ENDING_REGEX);
}
async getDiffForFilePath(filePath, {staged, baseCommit} = {}) {
let args = ['diff', '--no-prefix', '--no-renames', '--diff-filter=u'];
if (staged) { args.push('--staged'); }
if (baseCommit) { args.push(baseCommit); }
args = args.concat(['--', filePath]);
const output = await this.exec(args);
let rawDiffs = [];
if (output) { rawDiffs = parseDiff(output).filter(rawDiff => rawDiff.status !== 'unmerged'); }
if (!staged && (await this.getUntrackedFiles()).includes(filePath)) {
// add untracked file
const absPath = path.join(this.workingDir, filePath);
const executable = await isFileExecutable(absPath);
const contents = await readFile(absPath);
rawDiffs.push(buildAddedFilePatch(filePath, contents, executable));
}
if (rawDiffs.length > 1) { throw new Error(`Expected 0 or 1 diffs for ${filePath} but got ${rawDiffs.length}`); }
return rawDiffs[0];
}
async isPartiallyStaged(filePath) {
const args = ['status', '--short', '--', filePath];
const output = await this.exec(args, {writeOperation: true});
const results = output.trim().split(LINE_ENDING_REGEX);
if (results.length === 2) {
return true;
} else if (results.length === 1) {
return ['MM', 'AM', 'MD'].includes(results[0].slice(0, 2));
} else {
throw new Error(`Unexpected output for ${args.join(' ')}: ${output}`);
}
}
/**
* Miscellaneous getters
*/
async getCommit(ref) {
const output = await this.exec(['log', '--pretty=%H%x00%B%x00', '--no-abbrev-commit', '-1', ref]);
const [sha, message] = (output).split('\0');
return {sha, message: message.trim(), unbornRef: false};
}
async getHeadCommit() {
try {
const commit = await this.getCommit('HEAD');
commit.unbornRef = false;
return commit;
} catch (e) {
if (/unknown revision/.test(e.stdErr)) {
return {sha: '', message: '', unbornRef: true};
} else {
throw e;
}
}
}
readFileFromIndex(filePath) {
return this.exec(['show', `:${filePath}`]);
}
/**
* Merge
*/
merge(branchName) {
return this.gpgExec(['merge', branchName], {writeOperation: true});
}
async isMerging() {
try {
await readFile(path.join(this.workingDir, '.git', 'MERGE_HEAD'));
return true;
} catch (e) {
return false;
}
}
abortMerge() {
return this.exec(['merge', '--abort'], {writeOperation: true});
}
checkoutSide(side, paths) {
if (paths.length === 0) {
return Promise.resolve();
}
return this.exec(['checkout', `--${side}`, ...paths]);
}
/**
* Rebase
*/
async isRebasing() {
const results = await Promise.all([
fileExists(path.join(this.workingDir, '.git', 'rebase-merge')),
fileExists(path.join(this.workingDir, '.git', 'rebase-apply')),
]);
return results.some(r => r);
}
/**
* Remote interactions
*/
clone(remoteUrl, options = {}) {
const args = ['clone'];
if (options.noLocal) { args.push('--no-local'); }
if (options.bare) { args.push('--bare'); }
if (options.recursive) { args.push('--recursive'); }
args.push(remoteUrl, this.workingDir);
return this.exec(args, {writeOperation: true});
}
fetch(remote, branchName) {
return this.exec(['fetch', remote, branchName], {useGitPromptServer: true, writeOperation: true});
}
pull(remote, branchName) {
return this.gpgExec(['pull', remote, branchName], {useGitPromptServer: true, writeOperation: true});
}
push(remote, branchName, options = {}) {
const args = ['push', remote || 'origin', branchName];
if (options.setUpstream) { args.push('--set-upstream'); }
if (options.force) { args.push('--force'); }
return this.exec(args, {useGitPromptServer: true, writeOperation: true});
}
async getAheadCount(branchName) {
try {
const pushTrackingBranch = await this.exec(['rev-parse', '--symbolic-full-name', `${branchName}@{push}`]);
const output = await this.exec(['rev-list', `${pushTrackingBranch.trim()}..heads/${branchName}`]);
return output.trim().split(LINE_ENDING_REGEX).filter(s => s.trim()).length;
} catch (e) {
return null;
}
}
async getBehindCount(branchName) {
try {
const upstreamTrackingBranch = await this.exec(['rev-parse', '--symbolic-full-name', `${branchName}@{upstream}`]);
const output = await this.exec(['rev-list', `heads/${branchName}..${upstreamTrackingBranch.trim()}`]);
return output.trim().split(LINE_ENDING_REGEX).filter(s => s.trim()).length;
} catch (e) {
return null;
}
}
/**
* Branches
*/
async getCurrentBranch() {
const content = await readFile(path.join(this.workingDir, '.git', 'HEAD'));
if (content.startsWith('ref: ')) {
// The common case: you're on a branch
return {
name: (await this.exec(['symbolic-ref', '--short', 'HEAD'])).trim(),
isDetached: false,
};
} else {
// Detached HEAD
return {
name: (await this.exec(['describe', '--contains', '--all', 'HEAD'])).trim(),
isDetached: true,
};
}
}
checkout(branchName, options = {}) {
const args = ['checkout'];
if (options.createNew) { args.push('-b'); }
return this.exec(args.concat(branchName), {writeOperation: true});
}
checkoutFiles(paths, revision) {
if (paths.length === 0) { return null; }
const args = ['checkout'];
if (revision) { args.push(revision); }
return this.exec(args.concat('--', paths), {writeOperation: true});
}
async getBranches() {
const output = await this.exec(['for-each-ref', '--format=%(refname:short)', 'refs/heads/*']);
return output.trim().split(LINE_ENDING_REGEX);
}
async getConfig(option, {local} = {}) {
let output;
try {
let args = ['config'];
if (local) { args.push('--local'); }
args = args.concat(option);
output = await this.exec(args);
} catch (err) {
if (err.code === 1) {
// No matching config found
return null;
} else {
throw err;
}
}
return output.trim();
}
setConfig(option, value, {replaceAll} = {}) {
let args = ['config'];
if (replaceAll) { args.push('--replace-all'); }
args = args.concat(option, value);
return this.exec(args, {writeOperation: true});
}
async getRemotes() {
let output = await this.getConfig(['--get-regexp', '^remote..*.url$'], {local: true});
if (output) {
output = output.trim();
if (!output.length) { return []; }
return output.split('\n').map(line => {
const match = line.match(/^remote\.(.*)\.url (.*)$/);
return {
name: match[1],
url: match[2],
};
});
} else {
return [];
}
}
async createBlob({filePath, stdin} = {}) {
let output;
if (filePath) {
try {
output = (await this.exec(['hash-object', '-w', filePath], {writeOperation: true})).trim();
} catch (e) {
if (e.stdErr && e.stdErr.match(/fatal: Cannot open .*: No such file or directory/)) {
output = null;
} else {
throw e;
}
}
} else if (stdin) {
output = (await this.exec(['hash-object', '-w', '--stdin'], {stdin, writeOperation: true})).trim();
} else {
throw new Error('Must supply file path or stdin');
}
return output;
}
async expandBlobToFile(absFilePath, sha) {
const output = await this.exec(['cat-file', '-p', sha]);
await writeFile(absFilePath, output);
return absFilePath;
}
async getBlobContents(sha) {
return await this.exec(['cat-file', '-p', sha]);
}
async mergeFile(oursPath, commonBasePath, theirsPath, resultPath) {
const args = [
'merge-file', '-p', oursPath, commonBasePath, theirsPath,
'-L', 'current', '-L', 'after discard', '-L', 'before discard',
];
let output;
let conflict = false;
try {
output = await this.exec(args);
} catch (e) {
if (e instanceof GitError && e.code === 1) {
output = e.stdOut;
conflict = true;
} else {
throw e;
}
}
// Interpret a relative resultPath as relative to the repository working directory for consistency with the
// other arguments.
const resolvedResultPath = path.resolve(this.workingDir, resultPath);
await writeFile(resolvedResultPath, output);
return {filePath: oursPath, resultPath, conflict};
}
async writeMergeConflictToIndex(filePath, commonBaseSha, oursSha, theirsSha) {
const fileMode = await this.getFileMode(filePath);
let indexInfo = `0 0000000000000000000000000000000000000000\t${filePath}\n`;
if (commonBaseSha) { indexInfo += `${fileMode} ${commonBaseSha} 1\t${filePath}\n`; }
if (oursSha) { indexInfo += `${fileMode} ${oursSha} 2\t${filePath}\n`; }
if (theirsSha) { indexInfo += `${fileMode} ${theirsSha} 3\t${filePath}\n`; }
return this.exec(['update-index', '--index-info'], {stdin: indexInfo, writeOperation: true});
}
async getFileMode(filePath) {
const output = await this.exec(['ls-files', '--stage', '--', filePath]);
if (output) {
return output.slice(0, 6);
} else {
const executable = await isFileExecutable(path.join(this.workingDir, filePath));
return executable ? '100755' : '100644';
}
}
destroy() {
this.commandQueue.dispose();
}
}
function buildAddedFilePatch(filePath, contents, executable) {
const hunks = [];
if (contents) {
const noNewLine = contents[contents.length - 1] !== '\n';
const lines = contents.trim().split(LINE_ENDING_REGEX).map(line => `+${line}`);
if (noNewLine) { lines.push('\\ No newline at end of file'); }
hunks.push({
lines,
oldStartLine: 0,
oldLineCount: 0,
newStartLine: 1,
heading: '',
newLineCount: noNewLine ? lines.length - 1 : lines.length,
});
}
return {
oldPath: null,
newPath: filePath,
oldMode: null,
newMode: executable ? '100755' : '100644',
status: 'added',
hunks,
};
}