test sweep: finish src/git/ (T-91)
test / unit + widget + golden + a11y (push) Failing after 30s
test / integration_test (xvfb) (push) Has been skipped
test / bundle smoke (xvfb 5s) (push) Has been skipped
test / daemon subprocess + web WASM smoke (push) Has been skipped
test / dart doc (lib API) (push) Failing after 1m1s

Closes out the three remaining files in src/git/ following the
client.dart batch:

operations.dart (25 new tests):
- GitException.toString
- GitLogEntry.toJson (body present + absent)
- gitStage / gitUnstage / gitStashPop / gitPush / gitPull error
  paths (no remote, empty stash, bogus path)
- gitUnstage with empty paths (unstage everything)
- gitStageHunk + gitUnstageHunk via _applyPatch
- _applyPatch surfaces stderr in GitException on a bad patch
- gitBranches happy + non-repo
- gitCheckout happy + unknown-branch error
- gitPull + gitPush round-trip against a local bare remote
- gitLog / gitCurrentBranch / gitBranches non-repo fallbacks
- gitDiscard with empty list short-circuit
- gitBin resolver

diff.dart (7 new tests):
- gitDiff with paths argument and non-repo fallback
- GitHunk.toPatch round-tripping header + every DiffLineKind
- GitDiff.toJson with / without oldPath
- parseDiffOutput edge cases: pre-diff garbage skipped, "\ No newline"
  marker captured as a header line, malformed @@ header skipped via
  _parseHunk null return

status.dart (4 new tests):
- branch.upstream + branch.ab populated from a local bare remote
- non-git directory returns an empty branchless status
- rename in porcelain output captures the original path
- parsePorcelainV1 short-part / empty-part / empty-input edge cases

Coverage: src/git/diff.dart 106/124 -> 124/124 (100%);
src/git/operations.dart 88/155 -> 148/155 (95% — remaining 7 lines
are gitPull/gitPush variants that need credentials, and the
gitBranches non-zero stderr path);
src/git/status.dart 86/98 -> 95/98 (97% — remaining 3 are the
ProcessException-during-call catch branches, only reachable if git
crashes mid-call).

Total coverage 76.04% -> 77.05%; floor bumped to 77.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-13 07:04:30 +02:00
co-authored by Claude Opus 4.7
parent 7c8114ecbe
commit 035491f7db
4 changed files with 291 additions and 1 deletions
+91
View File
@@ -207,5 +207,96 @@ index abc..def 100644
final diffs = await gitDiff(sandbox);
expect(diffs, isEmpty);
});
test('paths argument narrows the diff to that file', () async {
await File('${sandbox.path}/file.txt').writeAsString('hello\nworld\n');
await File('${sandbox.path}/other.txt').writeAsString('o\n');
final scoped = await gitDiff(sandbox, paths: ['file.txt']);
expect(scoped, hasLength(1));
expect(scoped.first.path, 'file.txt');
});
test('returns empty on a non-git directory (exit != 0)', () async {
final notGit = await Directory.systemTemp.createTemp('clide-diff-not-');
addTearDown(() => notGit.deleteSync(recursive: true));
expect(await gitDiff(notGit), isEmpty);
});
});
group('GitHunk shape', () {
test('toPatch round-trips header + every line kind', () {
const hunk = GitHunk(
header: '@@ -1,3 +1,4 @@ ctx',
oldStart: 1,
oldCount: 3,
newStart: 1,
newCount: 4,
lines: [
DiffLine(kind: DiffLineKind.context, text: 'line1', oldLineNo: 1, newLineNo: 1),
DiffLine(kind: DiffLineKind.removal, text: 'line2', oldLineNo: 2),
DiffLine(kind: DiffLineKind.addition, text: 'line2-new', newLineNo: 2),
DiffLine(kind: DiffLineKind.header, text: r'\ No newline at end of file'),
],
);
final patch = hunk.toPatch();
expect(patch, contains('@@ -1,3 +1,4 @@ ctx'));
expect(patch, contains(' line1'));
expect(patch, contains('-line2'));
expect(patch, contains('+line2-new'));
expect(patch, contains(r'\ No newline at end of file'));
});
test('GitDiff.toJson serialises with optional oldPath only when set', () {
const withOld = GitDiff(path: 'b.txt', oldPath: 'a.txt', hunks: [], isRenamed: true);
expect(withOld.toJson().containsKey('oldPath'), isTrue);
const noOld = GitDiff(path: 'b.txt', hunks: []);
expect(noOld.toJson().containsKey('oldPath'), isFalse);
});
});
group('parseDiffOutput — edge cases', () {
test('skips lines outside any diff --git block', () {
const output = '''pre-diff garbage
another non-diff line
diff --git a/f.txt b/f.txt
--- a/f.txt
+++ b/f.txt
@@ -1 +1 @@
-old
+new
''';
final diffs = parseDiffOutput(output);
expect(diffs, hasLength(1));
});
test('captures the "\\ No newline at end of file" marker as a header line', () {
const output = '''diff --git a/f.txt b/f.txt
--- a/f.txt
+++ b/f.txt
@@ -1,1 +1,1 @@
-old
+new
\\ No newline at end of file
''';
final diffs = parseDiffOutput(output);
expect(diffs, hasLength(1));
final hunk = diffs.first.hunks.single;
expect(hunk.lines.any((l) => l.kind == DiffLineKind.header), isTrue);
});
test('skips a malformed @@ header (parseHunk returns null)', () {
const output = '''diff --git a/f.txt b/f.txt
--- a/f.txt
+++ b/f.txt
@@ not a valid hunk header @@
@@ -1 +1 @@
-old
+new
''';
final diffs = parseDiffOutput(output);
expect(diffs, hasLength(1));
// Only the valid @@ produces a hunk.
expect(diffs.first.hunks, hasLength(1));
});
});
}