diff --git a/lib/src/bindings/index.dart b/lib/src/bindings/index.dart index 5ae8db9..c7e1d06 100644 --- a/lib/src/bindings/index.dart +++ b/lib/src/bindings/index.dart @@ -292,7 +292,6 @@ void addFromBuffer({ void addAll({ required Pointer indexPointer, required List pathspec, - required int flags, }) { final pathspecC = calloc(); final pathPointers = pathspec.map((e) => e.toChar()).toList(); @@ -308,7 +307,7 @@ void addAll({ final error = libgit2.git_index_add_all( indexPointer, pathspecC, - flags, + 0, nullptr, nullptr, ); diff --git a/lib/src/bindings/merge.dart b/lib/src/bindings/merge.dart index 2e16d11..88229bf 100644 --- a/lib/src/bindings/merge.dart +++ b/lib/src/bindings/merge.dart @@ -186,39 +186,30 @@ String mergeFile({ libgit2.git_merge_file_input_init(theirsC, GIT_MERGE_FILE_INPUT_VERSION); ancestorC.ref.ptr = ancestor.toChar(); ancestorC.ref.size = ancestor.length; - Pointer ancestorLabelC = nullptr; oursC.ref.ptr = ours.toChar(); oursC.ref.size = ours.length; - Pointer oursLabelC = nullptr; theirsC.ref.ptr = theirs.toChar(); theirsC.ref.size = theirs.length; - Pointer theirsLabelC = nullptr; final opts = calloc(); libgit2.git_merge_file_options_init(opts, GIT_MERGE_FILE_OPTIONS_VERSION); opts.ref.favor = favor; opts.ref.flags = flags; if (ancestorLabel.isNotEmpty) { - ancestorLabelC = ancestorLabel.toChar(); - opts.ref.ancestor_label = ancestorLabelC; + opts.ref.ancestor_label = ancestorLabel.toChar(); } if (oursLabel.isNotEmpty) { - oursLabelC = oursLabel.toChar(); - opts.ref.our_label = oursLabelC; + opts.ref.our_label = oursLabel.toChar(); } if (theirsLabel.isNotEmpty) { - theirsLabelC = theirsLabel.toChar(); - opts.ref.their_label = theirsLabelC; + opts.ref.their_label = theirsLabel.toChar(); } libgit2.git_merge_file(out, ancestorC, oursC, theirsC, opts); calloc.free(ancestorC); - calloc.free(ancestorLabelC); calloc.free(oursC); - calloc.free(oursLabelC); calloc.free(theirsC); - calloc.free(theirsLabelC); calloc.free(opts); final result = out.ref.ptr.toDartString(length: out.ref.len); @@ -235,43 +226,17 @@ String mergeFile({ String mergeFileFromIndex({ required Pointer repoPointer, required Pointer? ancestorPointer, - required String ancestorLabel, required Pointer oursPointer, - required String oursLabel, required Pointer theirsPointer, - required String theirsLabel, - required int favor, - required int flags, }) { final out = calloc(); - final opts = calloc(); - Pointer ancestorLabelC = nullptr; - Pointer oursLabelC = nullptr; - Pointer theirsLabelC = nullptr; - - libgit2.git_merge_file_options_init(opts, GIT_MERGE_FILE_OPTIONS_VERSION); - opts.ref.favor = favor; - opts.ref.flags = flags; - if (ancestorLabel.isNotEmpty) { - ancestorLabelC = ancestorLabel.toChar(); - opts.ref.ancestor_label = ancestorLabelC; - } - if (oursLabel.isNotEmpty) { - oursLabelC = oursLabel.toChar(); - opts.ref.our_label = oursLabelC; - } - if (theirsLabel.isNotEmpty) { - theirsLabelC = theirsLabel.toChar(); - opts.ref.their_label = theirsLabelC; - } - final error = libgit2.git_merge_file_from_index( out, repoPointer, ancestorPointer ?? nullptr, oursPointer, theirsPointer, - opts, + nullptr, ); late final String result; @@ -279,10 +244,6 @@ String mergeFileFromIndex({ result = out.ref.ptr.toDartString(length: out.ref.len); } - calloc.free(ancestorLabelC); - calloc.free(oursLabelC); - calloc.free(theirsLabelC); - calloc.free(opts); calloc.free(out); if (error < 0) { diff --git a/lib/src/git_types.dart b/lib/src/git_types.dart index 65be8ed..564e960 100644 --- a/lib/src/git_types.dart +++ b/lib/src/git_types.dart @@ -1173,22 +1173,3 @@ enum GitBlobFilter { const GitBlobFilter(this.value); final int value; } - -/// Flags for APIs that add files matching pathspec. -enum GitIndexAddOption { - defaults(0), - - /// Skip the checking of ignore rules. - force(1), - - /// Disable glob expansion and force exact matching of files in working - /// directory. - disablePathspecMatch(2), - - /// Check that each entry in the pathspec is an exact match to a filename on - /// disk is either not ignored or already in the index. - checkPathspec(4); - - const GitIndexAddOption(this.value); - final int value; -} diff --git a/lib/src/index.dart b/lib/src/index.dart index 96ff8f8..63edaad 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -215,18 +215,9 @@ class Index with IterableMixin { /// that matches will be added to the index (either updating an existing /// entry or adding a new entry). /// - /// [flags] is optional combination of [GitIndexAddOption] flags. - /// /// Throws a [LibGit2Error] if error occured. - void addAll( - List pathspec, { - Set flags = const {GitIndexAddOption.defaults}, - }) { - bindings.addAll( - indexPointer: _indexPointer, - pathspec: pathspec, - flags: flags.fold(0, (acc, e) => acc | e.value), - ); + void addAll(List pathspec) { + bindings.addAll(indexPointer: _indexPointer, pathspec: pathspec); } /// Updates all index entries to match the working directory. diff --git a/lib/src/merge.dart b/lib/src/merge.dart index da080e0..015724b 100644 --- a/lib/src/merge.dart +++ b/lib/src/merge.dart @@ -265,43 +265,18 @@ class Merge { /// given common [ancestor] as the baseline, producing a string that reflects /// the merge result containing possible conflicts. /// - /// [ancestorLabel] is optional label for the ancestor file side of the - /// conflict which will be prepended to labels in diff3-format merge files. - /// - /// [oursLabel] is optional label for our file side of the conflict which - /// will be prepended to labels in merge files. - /// - /// [theirsLabel] is optional label for their file side of the conflict which - /// will be prepended to labels in merge files. - /// - /// [favor] is one of the [GitMergeFileFavor] flags for handling conflicting - /// content. Defaults to [GitMergeFileFavor.normal]. - /// - /// [flags] is a combination of [GitMergeFileFlag] flags. Defaults to - /// [GitMergeFileFlag.defaults]. - /// /// Throws a [LibGit2Error] if error occured. static String fileFromIndex({ required Repository repo, required IndexEntry? ancestor, - String ancestorLabel = '', required IndexEntry ours, - String oursLabel = '', required IndexEntry theirs, - String theirsLabel = '', - GitMergeFileFavor favor = GitMergeFileFavor.normal, - Set flags = const {GitMergeFileFlag.defaults}, }) { return bindings.mergeFileFromIndex( repoPointer: repo.pointer, ancestorPointer: ancestor?.pointer, - ancestorLabel: ancestorLabel, oursPointer: ours.pointer, - oursLabel: oursLabel, theirsPointer: theirs.pointer, - theirsLabel: theirsLabel, - favor: favor.value, - flags: flags.fold(0, (acc, e) => acc | e.value), ); } diff --git a/test/git_types_test.dart b/test/git_types_test.dart index cdbacaf..c0d81e9 100644 --- a/test/git_types_test.dart +++ b/test/git_types_test.dart @@ -551,15 +551,4 @@ void main() { expect(actual, expected); }); }); - - test('GitIndexAddOption returns correct values', () { - const expected = { - GitIndexAddOption.defaults: 0, - GitIndexAddOption.force: 1, - GitIndexAddOption.disablePathspecMatch: 2, - GitIndexAddOption.checkPathspec: 4, - }; - final actual = {for (final e in GitIndexAddOption.values) e: e.value}; - expect(actual, expected); - }); } diff --git a/test/index_test.dart b/test/index_test.dart index a681ad4..9a496a1 100644 --- a/test/index_test.dart +++ b/test/index_test.dart @@ -175,10 +175,7 @@ void main() { group('addAll()', () { test('adds with provided pathspec', () { index.clear(); - index.addAll( - ['file', 'feature_file'], - flags: {GitIndexAddOption.checkPathspec, GitIndexAddOption.force}, - ); + index.addAll(['file', 'feature_file']); expect(index.length, 2); expect(index['file'].oid.sha, fileSha); diff --git a/test/merge_test.dart b/test/merge_test.dart index 4b35d29..6f3a276 100644 --- a/test/merge_test.dart +++ b/test/merge_test.dart @@ -168,38 +168,31 @@ Another feature edit expect(diff, diffExpected); }); - test('merges with provided options', () { + test('merges with provided merge flags and file flags', () { const diffExpected = """ -\<<<<<<< ours -Feature edit on feature branch -||||||| ancestor -Feature edit +\<<<<<<< conflict_file +master conflict edit ======= -Another feature edit ->>>>>>> theirs +conflict branch edit +>>>>>>> conflict_file """; - Checkout.reference(repo: repo, name: 'refs/heads/feature'); - repo.setHead('refs/heads/feature'); - Merge.commit( repo: repo, commit: AnnotatedCommit.lookup( repo: repo, - oid: Branch.lookup(repo: repo, name: 'ancestor-conflict').target, + oid: Branch.lookup(repo: repo, name: 'conflict-branch').target, ), + mergeFlags: {GitMergeFlag.noRecursive}, + fileFlags: {GitMergeFileFlag.ignoreWhitespaceEOL}, ); - final conflictedFile = repo.index.conflicts['feature_file']!; + final conflictedFile = repo.index.conflicts['conflict_file']!; final diff = Merge.fileFromIndex( repo: repo, - ancestor: conflictedFile.ancestor, - ancestorLabel: 'ancestor', + ancestor: null, ours: conflictedFile.our!, - oursLabel: 'ours', theirs: conflictedFile.their!, - theirsLabel: 'theirs', - flags: {GitMergeFileFlag.styleDiff3}, ); expect(diff, diffExpected);