Skip to content

Commit ad159fc

Browse files
committed
fix(Git): Make sure foreign locks are freed when forceLock is set
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 9261b2b commit ad159fc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/lib/adapters/Git.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export default class GitAdapter extends CachingAdapter {
155155
clearInterval(this.lockingInterval)
156156
}
157157
if (forceLock) {
158+
await this.clearAllLocks()
158159
await this.setLock()
159160
} else if (needLock) {
160161
await this.obtainLock()
@@ -212,7 +213,7 @@ export default class GitAdapter extends CachingAdapter {
212213
})
213214
} catch (e) {
214215
if (e.code && e.code === git.Errors.PushRejectedError.code) {
215-
this.freeLock()
216+
await this.freeLock() // Only clears the locks set in the current adapter instance
216217
throw new ResourceLockedError
217218
}
218219
}
@@ -275,6 +276,14 @@ export default class GitAdapter extends CachingAdapter {
275276
}
276277
}
277278

279+
async clearAllLocks(): Promise<void> {
280+
const tags = await git.listTags({ fs: this.fs, dir: this.dir })
281+
const lockTags = tags.filter(tag => tag.startsWith('floccus-lock-'))
282+
for (const tag of lockTags) {
283+
await git.push({ fs: this.fs, http, dir: this.dir, ref: tag, delete: true, onAuth: () => this.onAuth() })
284+
}
285+
}
286+
278287
async pullFromServer() {
279288
let fileContents
280289
try {
@@ -369,11 +378,7 @@ export default class GitAdapter extends CachingAdapter {
369378
depth: 10,
370379
onAuth: () => this.onAuth()
371380
})
372-
const tags = await git.listTags({ fs, dir: this.dir })
373-
const lockTags = tags.filter(tag => tag.startsWith('floccus-lock-'))
374-
for (const tag of lockTags) {
375-
await git.push({ fs, http, dir: this.dir, ref: tag, delete: true, onAuth: () => this.onAuth() })
376-
}
381+
await this.clearAllLocks()
377382
}
378383
}
379384

0 commit comments

Comments
 (0)