isomorphic-git 1.17.3 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -611,6 +611,18 @@ export type SignCallback = (args: SignParams) => {
611
611
  } | Promise<{
612
612
  signature: string;
613
613
  }>;
614
+ export type MergeDriverParams = {
615
+ branches: string[];
616
+ contents: string[];
617
+ path: string;
618
+ };
619
+ export type MergeDriverCallback = (args: MergeDriverParams) => {
620
+ cleanMerge: boolean;
621
+ mergedText: string;
622
+ } | Promise<{
623
+ cleanMerge: boolean;
624
+ mergedText: string;
625
+ }>;
614
626
  export type RefUpdateStatus = {
615
627
  ok: boolean;
616
628
  error: string;
@@ -715,6 +727,7 @@ export var Errors: Readonly<{
715
727
  InvalidRefNameError: typeof InvalidRefNameError;
716
728
  MaxDepthError: typeof MaxDepthError;
717
729
  MergeNotSupportedError: typeof MergeNotSupportedError;
730
+ MergeConflictError: typeof MergeConflictError;
718
731
  MissingNameError: typeof MissingNameError;
719
732
  MissingParameterError: typeof MissingParameterError;
720
733
  MultipleGitError: typeof MultipleGitError;
@@ -2085,15 +2098,63 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2085
2098
  /**
2086
2099
  * Merge two branches
2087
2100
  *
2088
- * ## Limitations
2089
- *
2090
- * Currently it does not support incomplete merges. That is, if there are merge conflicts it cannot solve
2091
- * with the built in diff3 algorithm it will not modify the working dir, and will throw a [`MergeNotSupportedError`](./errors.md#mergenotsupportedError) error.
2092
- *
2093
2101
  * Currently it will fail if multiple candidate merge bases are found. (It doesn't yet implement the recursive merge strategy.)
2094
2102
  *
2095
2103
  * Currently it does not support selecting alternative merge strategies.
2096
2104
  *
2105
+ * Currently it is not possible to abort an incomplete merge. To restore the worktree to a clean state, you will need to checkout an earlier commit.
2106
+ *
2107
+ * Currently it does not directly support the behavior of `git merge --continue`. To complete a merge after manual conflict resolution, you will need to add and commit the files manually, and specify the appropriate parent commits.
2108
+ *
2109
+ * ## Manually resolving merge conflicts
2110
+ * By default, if isomorphic-git encounters a merge conflict it cannot resolve using the builtin diff3 algorithm or provided merge driver, it will abort and throw a `MergeNotSupportedError`.
2111
+ * This leaves the index and working tree untouched.
2112
+ *
2113
+ * When `abortOnConflict` is set to `false`, and a merge conflict cannot be automatically resolved, a `MergeConflictError` is thrown and the results of the incomplete merge will be written to the working directory.
2114
+ * This includes conflict markers in files with unresolved merge conflicts.
2115
+ *
2116
+ * To complete the merge, edit the conflicting files as you see fit, and then add and commit the resolved merge.
2117
+ *
2118
+ * For a proper merge commit, be sure to specify the branches or commits you are merging in the `parent` argument to `git.commit`.
2119
+ * For example, say we are merging the branch `feature` into the branch `main` and there is a conflict we want to resolve manually.
2120
+ * The flow would look like this:
2121
+ *
2122
+ * ```
2123
+ * await git.merge({
2124
+ * fs,
2125
+ * dir,
2126
+ * ours: 'main',
2127
+ * theirs: 'feature',
2128
+ * abortOnConflict: false,
2129
+ * }).catch(e => {
2130
+ * if (e instanceof Errors.MergeConflictError) {
2131
+ * console.log(
2132
+ * 'Automatic merge failed for the following files: '
2133
+ * + `${e.data}. `
2134
+ * + 'Resolve these conflicts and then commit your changes.'
2135
+ * )
2136
+ * } else throw e
2137
+ * })
2138
+ *
2139
+ * // This is the where we manually edit the files that have been written to the working directory
2140
+ * // ...
2141
+ * // Files have been edited and we are ready to commit
2142
+ *
2143
+ * await git.add({
2144
+ * fs,
2145
+ * dir,
2146
+ * filepath: '.',
2147
+ * })
2148
+ *
2149
+ * await git.commit({
2150
+ * fs,
2151
+ * dir,
2152
+ * ref: 'main',
2153
+ * message: "Merge branch 'feature' into main",
2154
+ * parent: ['main', 'feature'], // Be sure to specify the parents when creating a merge commit
2155
+ * })
2156
+ * ```
2157
+ *
2097
2158
  * @param {object} args
2098
2159
  * @param {FsClient} args.fs - a file system client
2099
2160
  * @param {SignCallback} [args.onSign] - a PGP signing implementation
@@ -2105,6 +2166,7 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2105
2166
  * @param {boolean} [args.fastForwardOnly = false] - If true, then non-fast-forward merges will throw an Error instead of performing a merge.
2106
2167
  * @param {boolean} [args.dryRun = false] - If true, simulates a merge so you can test whether it would succeed.
2107
2168
  * @param {boolean} [args.noUpdateBranch = false] - If true, does not update the branch pointer after creating the commit.
2169
+ * @param {boolean} [args.abortOnConflict = true] - If true, merges with conflicts will not update the worktree or index.
2108
2170
  * @param {string} [args.message] - Overrides the default auto-generated merge commit message
2109
2171
  * @param {Object} [args.author] - passed to [commit](commit.md) when creating a merge commit
2110
2172
  * @param {string} [args.author.name] - Default is `user.name` config.
@@ -2118,6 +2180,7 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2118
2180
  * @param {number} [args.committer.timezoneOffset] - Set the committer timezone offset field. This is the difference, in minutes, from the current timezone to UTC. Default is `(new Date()).getTimezoneOffset()`.
2119
2181
  * @param {string} [args.signingKey] - passed to [commit](commit.md) when creating a merge commit
2120
2182
  * @param {object} [args.cache] - a [cache](cache.md) object
2183
+ * @param {MergeDriverCallback} [args.mergeDriver] - a [merge driver](mergeDriver.md) implementation
2121
2184
  *
2122
2185
  * @returns {Promise<MergeResult>} Resolves to a description of the merge operation
2123
2186
  * @see MergeResult
@@ -2132,7 +2195,7 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2132
2195
  * console.log(m)
2133
2196
  *
2134
2197
  */
2135
- export function merge({ fs: _fs, onSign, dir, gitdir, ours, theirs, fastForward, fastForwardOnly, dryRun, noUpdateBranch, message, author: _author, committer: _committer, signingKey, cache, }: {
2198
+ export function merge({ fs: _fs, onSign, dir, gitdir, ours, theirs, fastForward, fastForwardOnly, dryRun, noUpdateBranch, abortOnConflict, message, author: _author, committer: _committer, signingKey, cache, mergeDriver, }: {
2136
2199
  fs: CallbackFsClient | PromiseFsClient;
2137
2200
  onSign?: SignCallback;
2138
2201
  dir?: string;
@@ -2143,6 +2206,7 @@ export function merge({ fs: _fs, onSign, dir, gitdir, ours, theirs, fastForward,
2143
2206
  fastForwardOnly?: boolean;
2144
2207
  dryRun?: boolean;
2145
2208
  noUpdateBranch?: boolean;
2209
+ abortOnConflict?: boolean;
2146
2210
  message?: string;
2147
2211
  author?: {
2148
2212
  name?: string;
@@ -2158,6 +2222,7 @@ export function merge({ fs: _fs, onSign, dir, gitdir, ours, theirs, fastForward,
2158
2222
  };
2159
2223
  signingKey?: string;
2160
2224
  cache?: any;
2225
+ mergeDriver?: MergeDriverCallback;
2161
2226
  }): Promise<MergeResult>;
2162
2227
  /**
2163
2228
  *
@@ -3864,6 +3929,21 @@ declare namespace MergeNotSupportedError {
3864
3929
  const code_13: 'MergeNotSupportedError';
3865
3930
  export { code_13 as code };
3866
3931
  }
3932
+ declare class MergeConflictError extends BaseError {
3933
+ /**
3934
+ * @param {Array<string>} filepaths
3935
+ */
3936
+ constructor(filepaths: string[]);
3937
+ code: "MergeConflictError";
3938
+ name: "MergeConflictError";
3939
+ data: {
3940
+ filepaths: string[];
3941
+ };
3942
+ }
3943
+ declare namespace MergeConflictError {
3944
+ const code_14: 'MergeConflictError';
3945
+ export { code_14 as code };
3946
+ }
3867
3947
  declare class MissingNameError extends BaseError {
3868
3948
  /**
3869
3949
  * @param {'author'|'committer'|'tagger'} role
@@ -3876,8 +3956,8 @@ declare class MissingNameError extends BaseError {
3876
3956
  };
3877
3957
  }
3878
3958
  declare namespace MissingNameError {
3879
- const code_14: 'MissingNameError';
3880
- export { code_14 as code };
3959
+ const code_15: 'MissingNameError';
3960
+ export { code_15 as code };
3881
3961
  }
3882
3962
  declare class MissingParameterError extends BaseError {
3883
3963
  /**
@@ -3891,8 +3971,8 @@ declare class MissingParameterError extends BaseError {
3891
3971
  };
3892
3972
  }
3893
3973
  declare namespace MissingParameterError {
3894
- const code_15: 'MissingParameterError';
3895
- export { code_15 as code };
3974
+ const code_16: 'MissingParameterError';
3975
+ export { code_16 as code };
3896
3976
  }
3897
3977
  declare class MultipleGitError extends BaseError {
3898
3978
  /**
@@ -3908,8 +3988,8 @@ declare class MultipleGitError extends BaseError {
3908
3988
  errors: Error[];
3909
3989
  }
3910
3990
  declare namespace MultipleGitError {
3911
- const code_16: 'MultipleGitError';
3912
- export { code_16 as code };
3991
+ const code_17: 'MultipleGitError';
3992
+ export { code_17 as code };
3913
3993
  }
3914
3994
  declare class NoRefspecError extends BaseError {
3915
3995
  /**
@@ -3923,8 +4003,8 @@ declare class NoRefspecError extends BaseError {
3923
4003
  };
3924
4004
  }
3925
4005
  declare namespace NoRefspecError {
3926
- const code_17: 'NoRefspecError';
3927
- export { code_17 as code };
4006
+ const code_18: 'NoRefspecError';
4007
+ export { code_18 as code };
3928
4008
  }
3929
4009
  declare class NotFoundError extends BaseError {
3930
4010
  /**
@@ -3938,8 +4018,8 @@ declare class NotFoundError extends BaseError {
3938
4018
  };
3939
4019
  }
3940
4020
  declare namespace NotFoundError {
3941
- const code_18: 'NotFoundError';
3942
- export { code_18 as code };
4021
+ const code_19: 'NotFoundError';
4022
+ export { code_19 as code };
3943
4023
  }
3944
4024
  declare class ObjectTypeError extends BaseError {
3945
4025
  /**
@@ -3959,8 +4039,8 @@ declare class ObjectTypeError extends BaseError {
3959
4039
  };
3960
4040
  }
3961
4041
  declare namespace ObjectTypeError {
3962
- const code_19: 'ObjectTypeError';
3963
- export { code_19 as code };
4042
+ const code_20: 'ObjectTypeError';
4043
+ export { code_20 as code };
3964
4044
  }
3965
4045
  declare class ParseError extends BaseError {
3966
4046
  /**
@@ -3976,8 +4056,8 @@ declare class ParseError extends BaseError {
3976
4056
  };
3977
4057
  }
3978
4058
  declare namespace ParseError {
3979
- const code_20: 'ParseError';
3980
- export { code_20 as code };
4059
+ const code_21: 'ParseError';
4060
+ export { code_21 as code };
3981
4061
  }
3982
4062
  declare class PushRejectedError extends BaseError {
3983
4063
  /**
@@ -3991,8 +4071,8 @@ declare class PushRejectedError extends BaseError {
3991
4071
  };
3992
4072
  }
3993
4073
  declare namespace PushRejectedError {
3994
- const code_21: 'PushRejectedError';
3995
- export { code_21 as code };
4074
+ const code_22: 'PushRejectedError';
4075
+ export { code_22 as code };
3996
4076
  }
3997
4077
  declare class RemoteCapabilityError extends BaseError {
3998
4078
  /**
@@ -4008,8 +4088,8 @@ declare class RemoteCapabilityError extends BaseError {
4008
4088
  };
4009
4089
  }
4010
4090
  declare namespace RemoteCapabilityError {
4011
- const code_22: 'RemoteCapabilityError';
4012
- export { code_22 as code };
4091
+ const code_23: 'RemoteCapabilityError';
4092
+ export { code_23 as code };
4013
4093
  }
4014
4094
  declare class SmartHttpError extends BaseError {
4015
4095
  /**
@@ -4025,8 +4105,8 @@ declare class SmartHttpError extends BaseError {
4025
4105
  };
4026
4106
  }
4027
4107
  declare namespace SmartHttpError {
4028
- const code_23: 'SmartHttpError';
4029
- export { code_23 as code };
4108
+ const code_24: 'SmartHttpError';
4109
+ export { code_24 as code };
4030
4110
  }
4031
4111
  declare class UnknownTransportError extends BaseError {
4032
4112
  /**
@@ -4044,8 +4124,8 @@ declare class UnknownTransportError extends BaseError {
4044
4124
  };
4045
4125
  }
4046
4126
  declare namespace UnknownTransportError {
4047
- const code_24: 'UnknownTransportError';
4048
- export { code_24 as code };
4127
+ const code_25: 'UnknownTransportError';
4128
+ export { code_25 as code };
4049
4129
  }
4050
4130
  declare class UnsafeFilepathError extends BaseError {
4051
4131
  /**
@@ -4059,8 +4139,8 @@ declare class UnsafeFilepathError extends BaseError {
4059
4139
  };
4060
4140
  }
4061
4141
  declare namespace UnsafeFilepathError {
4062
- const code_25: 'UnsafeFilepathError';
4063
- export { code_25 as code };
4142
+ const code_26: 'UnsafeFilepathError';
4143
+ export { code_26 as code };
4064
4144
  }
4065
4145
  declare class UrlParseError extends BaseError {
4066
4146
  /**
@@ -4074,8 +4154,8 @@ declare class UrlParseError extends BaseError {
4074
4154
  };
4075
4155
  }
4076
4156
  declare namespace UrlParseError {
4077
- const code_26: 'UrlParseError';
4078
- export { code_26 as code };
4157
+ const code_27: 'UrlParseError';
4158
+ export { code_27 as code };
4079
4159
  }
4080
4160
  declare class UserCanceledError extends BaseError {
4081
4161
  code: "UserCanceledError";
@@ -4083,8 +4163,8 @@ declare class UserCanceledError extends BaseError {
4083
4163
  data: {};
4084
4164
  }
4085
4165
  declare namespace UserCanceledError {
4086
- const code_27: 'UserCanceledError';
4087
- export { code_27 as code };
4166
+ const code_28: 'UserCanceledError';
4167
+ export { code_28 as code };
4088
4168
  }
4089
4169
  /**
4090
4170
  * @typedef {Object} GitProgressEvent
@@ -4287,6 +4367,17 @@ declare namespace UserCanceledError {
4287
4367
  * @param {SignParams} args
4288
4368
  * @return {{signature: string} | Promise<{signature: string}>} - an 'ASCII armor' encoded "detached" signature
4289
4369
  */
4370
+ /**
4371
+ * @typedef {Object} MergeDriverParams
4372
+ * @property {Array<string>} branches
4373
+ * @property {Array<string>} contents
4374
+ * @property {string} path
4375
+ */
4376
+ /**
4377
+ * @callback MergeDriverCallback
4378
+ * @param {MergeDriverParams} args
4379
+ * @return {{cleanMerge: boolean, mergedText: string} | Promise<{cleanMerge: boolean, mergedText: string}>}
4380
+ */
4290
4381
  /**
4291
4382
  * @callback WalkerMap
4292
4383
  * @param {string} filename