diff --git a/CHANGELOG.md b/CHANGELOG.md index 5512dbda..be3dc688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/git_dir.dart b/lib/src/git_dir.dart index abf03189..a9487ad4 100644 --- a/lib/src/git_dir.dart +++ b/lib/src/git_dir.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:path/path.dart' as p; @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index b5bf1d7c..3bde6be8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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. diff --git a/test/git_dir_test.dart b/test/git_dir_test.dart index 275af7ec..22e71e31 100644 --- a/test/git_dir_test.dart +++ b/test/git_dir_test.dart @@ -335,7 +335,7 @@ Future _testPopulateBranch() async { gd1, testBranchName, testContent2, - 'second commit', + 'second commit\n\nThis is some other content\nDoes this work?', ); await _testPopulateBranchWithDupeContent( @@ -349,7 +349,11 @@ Future _testPopulateBranch() async { gd1, testBranchName, testContent1, - '3rd commit, content 1', + ''' +3rd commit, content 1 + +With some new lines +and more messages''', ); _testPopulateBranchEmpty(gd1, testBranchName);