Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
sdk: [dev, 3.4]
sdk: [dev, 3.9]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
Expand All @@ -47,7 +47,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest, macos-latest, windows-latest]
sdk: [dev, 3.4]
sdk: [dev, 3.9]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.3-wip

- Require Dart 3.9

## 2.3.2

- Fix `GitDir` constructor when in a submodule.
Expand Down
5 changes: 3 additions & 2 deletions lib/src/commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ class Commit {
final treeSha = headers['tree']!.single;
final author = headers['author']!.single;
final committer = headers['committer']!.single;
final commitSha =
headers.containsKey('commit') ? headers['commit']!.single : null;
final commitSha = headers.containsKey('commit')
? headers['commit']!.single
: null;

final parents = headers['parent'] ?? [];

Expand Down
94 changes: 56 additions & 38 deletions lib/src/git_dir.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class GitDir {
final String? _gitWorkTree;

GitDir._raw(this.path, {String? gitWorkTree})
: assert(p.isAbsolute(path)),
assert(gitWorkTree == null || p.isAbsolute(gitWorkTree)),
_gitWorkTree = gitWorkTree;
: assert(p.isAbsolute(path)),
assert(gitWorkTree == null || p.isAbsolute(gitWorkTree)),
_gitWorkTree = gitWorkTree;

Future<int> commitCount([String branchName = 'HEAD']) async {
final pr = await runCommand(['rev-list', '--count', branchName]);
Expand Down Expand Up @@ -68,10 +68,7 @@ class GitDir {

for (var ref in refs) {
final pr = await runCommand(['cat-file', '-p', ref.sha]);
yield Tag.parseCatFile(
pr.stdout as String,
ref,
);
yield Tag.parseCatFile(pr.stdout as String, ref);
}
}

Expand Down Expand Up @@ -103,17 +100,22 @@ class GitDir {
}

Future<BranchReference> currentBranch() async {
var pr = await runCommand(
const ['rev-parse', '--verify', '--symbolic-full-name', 'HEAD'],
);
var pr = await runCommand(const [
'rev-parse',
'--verify',
'--symbolic-full-name',
'HEAD',
]);

pr = await runCommand(
['show-ref', '--verify', (pr.stdout as String).trim()],
);
pr = await runCommand([
'show-ref',
'--verify',
(pr.stdout as String).trim(),
]);

return CommitReference.fromShowRefOutput(pr.stdout as String)
.single
.toBranchReference();
return CommitReference.fromShowRefOutput(
pr.stdout as String,
).single.toBranchReference();
}

Future<List<TreeEntry>> lsTree(
Expand Down Expand Up @@ -155,8 +157,11 @@ class GitDir {
if (targetBranchRef == null) {
newCommitSha = await commitTree(treeSha, commitMessage);
} else {
newCommitSha =
await _updateBranch(targetBranchRef.sha, treeSha, commitMessage);
newCommitSha = await _updateBranch(
targetBranchRef.sha,
treeSha,
commitMessage,
);
}

if (newCommitSha == null) {
Expand Down Expand Up @@ -292,8 +297,10 @@ class GitDir {
);
}

Future<bool> isWorkingTreeClean() => runCommand(['status', '--porcelain'])
.then((pr) => (pr.stdout as String).isEmpty);
Future<bool> isWorkingTreeClean() => runCommand([
'status',
'--porcelain',
]).then((pr) => (pr.stdout as String).isEmpty);

// TODO: TEST: someone puts a git dir when populated
// TODO: TEST: someone puts in no content at all
Expand Down Expand Up @@ -340,16 +347,21 @@ class GitDir {
) async {
final tempGitRoot = await _createTempDir();

final tempGitDir =
GitDir._raw(tempGitRoot.path, gitWorkTree: sourceDirectoryPath);
final tempGitDir = GitDir._raw(
tempGitRoot.path,
gitWorkTree: sourceDirectoryPath,
);

// time for crazy clone tricks
final args = ['clone', '--shared', '--bare', path, '.'];

await runGit(args, processWorkingDir: tempGitDir.path);

await tempGitDir
.runCommand(['symbolic-ref', 'HEAD', 'refs/heads/$branchName']);
await tempGitDir.runCommand([
'symbolic-ref',
'HEAD',
'refs/heads/$branchName',
]);

try {
// make sure there is something in the working three
Expand All @@ -371,10 +383,7 @@ class GitDir {
return null;
}

final args = [
'commit',
'--verbose',
];
final args = ['commit', '--verbose'];

Directory? tmpDir;

Expand All @@ -401,8 +410,13 @@ class GitDir {
}

// --verbose is not strictly needed, but nice for debugging
await tempGitDir
.runCommand(['push', '--verbose', '--progress', path, branchName]);
await tempGitDir.runCommand([
'push',
'--verbose',
'--progress',
path,
branchName,
]);

// pr.stderr will have all of the info

Expand Down Expand Up @@ -461,10 +475,10 @@ class GitDir {

// `--show-toplevel` returns a canonicalized absolute path
// with all symlinks resolved.
final pr = await runGit(
['rev-parse', '--show-toplevel'],
processWorkingDir: path.toString(),
);
final pr = await runGit([
'rev-parse',
'--show-toplevel',
], processWorkingDir: path.toString());

final returnedPath = (pr.stdout as String).trim();

Expand All @@ -476,15 +490,19 @@ class GitDir {
return GitDir._raw(returnedPath);
}

throw ArgumentError('The provided value "$gitDirRoot" is not '
'the root of a git directory');
throw ArgumentError(
'The provided value "$gitDirRoot" is not '
'the root of a git directory',
);
}

static Future<GitDir> _init(Directory source, {String? branchName}) async {
final isGitDir = await _isGitDir(source);
if (isGitDir) {
throw ArgumentError('Cannot init a directory that is already a '
'git directory');
throw ArgumentError(
'Cannot init a directory that is already a '
'git directory',
);
}

await runGit([
Expand Down
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: git
version: 2.3.2
version: 2.3.3-wip
description: >-
Git command line wrapper. Exposes a Git directory abstraction that makes it
easy to inspect and manipulate a local Git repository.
repository: https://github.com/kevmoo/git

environment:
sdk: ^3.4.0
sdk: ^3.9.0

dependencies:
path: ^1.0.0
path: ^1.8.0

dev_dependencies:
checks: ^0.3.1
dart_flutter_team_lints: ^3.0.0
test: ^1.6.0
test: ^1.24.0
test_descriptor: ^2.0.0
Loading