@dotinc/ogre 0.12.0 → 0.13.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.
package/src/repository.ts CHANGED
@@ -107,6 +107,11 @@ export interface RepositoryObject<T extends { [k: string]: any }> {
107
107
  * Cherry returns the commits that are missing from upstream and the refs that have been moved since remote
108
108
  */
109
109
  cherry(): { commits: Array<Commit>; refs: Map<string, Reference> };
110
+
111
+ /**
112
+ * Runs an arbitrary backend push command and after success advances the locally stored remote state
113
+ */
114
+ push(pushToBackendFn: () => Promise<boolean>): Promise<boolean>
110
115
  }
111
116
 
112
117
  /**
@@ -119,12 +124,7 @@ export class Repository<T extends { [k: PropertyKey]: any }>
119
124
  this.hashFn = options.overrides?.calculateCommitHashFn;
120
125
  this.serializeObjectFn = options.overrides?.serializeObjectFn;
121
126
  this.deserializeObjectFn = options.overrides?.deserializeObjectFn;
122
- // FIXME: move this to refs/remote as git would do?
123
- this.remoteRefs = immutableMapCopy(options.history?.refs);
124
- this.remoteCommits = immutableArrayCopy<Commit, string>(
125
- options.history?.commits,
126
- (c) => c.hash,
127
- );
127
+ options.history && this.storeRemoteState(options.history);
128
128
  this.original = deepClone(obj);
129
129
  // store js ref, so obj can still be modified without going through repo.data
130
130
  this.data = obj as T;
@@ -159,6 +159,15 @@ export class Repository<T extends { [k: PropertyKey]: any }>
159
159
  });
160
160
  }
161
161
 
162
+ private storeRemoteState(history: History) {
163
+ // FIXME: move this to refs/remote as git would do?
164
+ this.remoteRefs = immutableMapCopy(history.refs);
165
+ this.remoteCommits = immutableArrayCopy<Commit, string>(
166
+ history.commits,
167
+ (c) => c.hash,
168
+ );
169
+ }
170
+
162
171
  private readonly original: T;
163
172
  private _isReady = false;
164
173
 
@@ -192,18 +201,26 @@ export class Repository<T extends { [k: PropertyKey]: any }>
192
201
  | undefined;
193
202
 
194
203
  // stores the remote state upon initialization
195
- private readonly remoteRefs:
204
+ private remoteRefs:
196
205
  | ReadonlyMap<string, Readonly<Reference>>
197
206
  | undefined;
198
207
 
199
208
  // stores the remote state upon initialization
200
- private readonly remoteCommits: ReadonlyArray<Readonly<string>> | undefined;
209
+ private remoteCommits: ReadonlyArray<Readonly<string>> | undefined;
201
210
 
202
211
  private observer: Observer<T>;
203
212
 
204
213
  private readonly refs: Map<string, Reference>;
205
214
  private readonly commits: Array<Commit>;
206
215
 
216
+ async push(pushToBackendFn: () => Promise<boolean>): Promise<boolean> {
217
+ const success = await pushToBackendFn()
218
+ if (success) {
219
+ this.storeRemoteState(this.getHistory())
220
+ }
221
+ return success
222
+ }
223
+
207
224
  cherry(): { commits: Array<Commit>; refs: Map<string, Reference> } {
208
225
  const commits: Array<Commit> = [];
209
226
  const refs = new Map<string, Reference>();