+
Skip to content

handle multi-line commit messages on Windows #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2023
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 2.2.1-dev
## 2.2.1

- Correctly handle multi-line commit messages on Windows.
- Require Dart 2.19

## 2.2.0
Expand Down
31 changes: 29 additions & 2 deletions lib/src/git_dir.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as p;
Expand Down Expand Up @@ -362,8 +363,34 @@ class GitDir {
return null;
}

// Time to commit.
await tempGitDir.runCommand(['commit', '--verbose', '-m', commitMessage]);
final args = [
'commit',
'--verbose',
];

Directory? tmpDir;

if (LineSplitter.split(commitMessage).length > 1 && Platform.isWindows) {
tmpDir = Directory.systemTemp.createTempSync('pkg_git_');

final fileName = p.join(tmpDir.path, 'commit_message.txt');
File(fileName).writeAsStringSync(
commitMessage,
mode: FileMode.writeOnly,
flush: true,
);

args.addAll(['--file', fileName]);
} else {
args.addAll(['-m', commitMessage]);
}

try {
// Time to commit.
await tempGitDir.runCommand(args);
} finally {
tmpDir?.deleteSync(recursive: true);
}

// --verbose is not strictly needed, but nice for debugging
await tempGitDir
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.2.1-dev
version: 2.2.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
8 changes: 6 additions & 2 deletions test/git_dir_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Future<void> _testPopulateBranch() async {
gd1,
testBranchName,
testContent2,
'second commit',
'second commit\n\nThis is some other content\nDoes this work?',
);

await _testPopulateBranchWithDupeContent(
Expand All @@ -349,7 +349,11 @@ Future<void> _testPopulateBranch() async {
gd1,
testBranchName,
testContent1,
'3rd commit, content 1',
'''
3rd commit, content 1

With some new lines
and more messages''',
);

_testPopulateBranchEmpty(gd1, testBranchName);
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载