Skip to content

Commit

Permalink
Correctly support default git configuration RE bareRepository = explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Feb 6, 2025
1 parent 924621d commit 2f2931e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.1

* Fix `safe.bareRepository = explicit` git configuration.

## 2.3.0

- Added support for lightweight tags.
Expand Down
41 changes: 22 additions & 19 deletions lib/src/git_dir.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import 'util.dart';

/// Represents a local directory
class GitDir {
static const _workTreeArg = '--work-tree=';
static const _gitDirArg = '--git-dir=';
static const _workTreeArg = '--work-tree';
static const _gitDirArg = '--git-dir';

final String _path;
final String path;
final String? _gitWorkTree;

GitDir._raw(this._path, [this._gitWorkTree])
: assert(p.isAbsolute(_path)),
assert(_gitWorkTree == null || p.isAbsolute(_gitWorkTree));

String get path => _path;
GitDir._raw(this.path, {String? 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 @@ -96,8 +95,9 @@ class GitDir {
return [];
}

// otherwise, it should have worked fine...
assert(pr.exitCode == 0);
if (pr.exitCode != 0) {
throw ProcessException('git', args, pr.stderr as String, pr.exitCode);
}

return CommitReference.fromShowRefOutput(pr.stdout as String);
}
Expand Down Expand Up @@ -276,14 +276,18 @@ class GitDir {
);
}

if (_gitWorkTree != null) {
list.insert(0, '$_workTreeArg$_gitWorkTree');
}

return runGit(
list,
[
if (_gitWorkTree != null) ...[
_gitDirArg,
path,
_workTreeArg,
_gitWorkTree,
],
...list,
],
throwOnError: throwOnError,
processWorkingDir: _processWorkingDir,
processWorkingDir: path,
echoOutput: echoOutput,
);
}
Expand Down Expand Up @@ -336,7 +340,8 @@ class GitDir {
) async {
final tempGitRoot = await _createTempDir();

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

// time for crazy clone tricks
final args = ['clone', '--shared', '--bare', path, '.'];
Expand Down Expand Up @@ -409,8 +414,6 @@ class GitDir {
}
}

String get _processWorkingDir => _path.toString();

static Future<bool> isGitDir(String path) async {
final dir = Directory(path);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: git
version: 2.3.0
version: 2.3.1
description: >-
Git command line wrapper. Exposes a Git directory abstraction that makes it
easy to inspect and manipulate a local Git repository.
Expand Down

0 comments on commit 2f2931e

Please sign in to comment.