forked from sebastiande/insomnia-plugin-git-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyncToServer.js
More file actions
37 lines (32 loc) · 1.37 KB
/
SyncToServer.js
File metadata and controls
37 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const Sync = require('./Sync');
class SyncToServer {
async push(context, data, expFilename) {
const sGit = Sync.getSimpleGit(context, data.workspace);
try {
await sGit.add(expFilename);
await sGit.commit('Commit');
await sGit.push();
} catch(error) {
console.error(error);
await this.handleError(error, sGit, context);
return;
}
// noinspection JSUnresolvedVariable,JSCheckFunctionSignatures
context.app.alert('Success!', 'Pushed to server.');
}
async handleError(error, sGit, context) {
if (!error.message.includes('CONFLICT')) {
// noinspection JSUnresolvedVariable,JSCheckFunctionSignatures
context.app.alert('Error!', 'Could not update the project, more information can be found in console!');
return;
}
// TODO as soon as there is an api from insomnia for yes/now dialogs we should switch to it
if (confirm('There are conflicts, do you want to overwrite the server version with your local one?')) {
sGit.push(['-f'], () => {
// noinspection JSUnresolvedVariable,JSCheckFunctionSignatures
context.app.alert('Finished', 'Server version got overwritten with your local one.');
});
}
}
}
module.exports = new SyncToServer();