Skip to content

Instantly share code, notes, and snippets.

@houkanshan
Created May 16, 2020 21:38
Show Gist options
  • Save houkanshan/f966c1aadc3f73f5d1b1e1e522ae2414 to your computer and use it in GitHub Desktop.
Save houkanshan/f966c1aadc3f73f5d1b1e1e522ae2414 to your computer and use it in GitHub Desktop.
const path = require('path')
function checkModule(name, sendMessage) {
try {
const m = require(name)
} catch(e) {
sendMessage(e)
throw e
}
}
exports.execute = async (args) => {
// args => https://egodigital.github.io/vscode-powertools/api/interfaces/_contracts_.jobitemscriptactionarguments.html
// s. https://code.visualstudio.com/api/references/vscode-api
const vscode = args.require('vscode')
const logger = args.logger
checkModule('simple-git/promise', vscode.window.showInformationMessage)
const simplegit = require('simple-git/promise')
const workspace = vscode.workspace.workspaceFolders[0].uri
const git = simplegit(workspace.fsPath)
await git.add('.' + path.sep + '*')
const status = await git.status()
logger.trace(JSON.stringify(status))
const changes = status.modified.length + status.created.length + status.deleted.length + status.renamed.length
if (changes > 0) {
await git.commit('Update by auto-git.ts')
logger.trace('commit')
await git.pull()
logger.trace('pull')
const result = await git.push(status.tracking)
logger.trace(JSON.stringify(result))
//vscode.window.showInformationMessage("Git sync finished")
} else {
logger.trace('pull')
await git.pull()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment