forked from Aghabeiki/gitdiffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
69 lines (53 loc) · 2.32 KB
/
extension.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
'use strict';
var vscode = require('vscode');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
var gitDiffer = vscode.commands.registerCommand('extension.gitDiffer', function (param) {
if (param == undefined ||param._resourceUri.scheme !== 'file' ) {
vscode.window.showWarningMessage('Command should be run from source control context menu');
return;
} else {
var simpleGit = require('simple-git');
var projectPath = (vscode.workspace.rootPath)
var targetFile=param._resourceUri.fsPath.replace(projectPath,'');
// remove first / or \
if(targetFile[0]=== '/' || targetFile[0]=='\\'){
targetFile=targetFile.slice(1,targetFile.length );
}
simpleGit(projectPath).raw(
[
'difftool',
'-y',
targetFile
], (err, result) => {
if(err)
vscode.showWarningMessage(err)
console.log(err);
console.log(result);
});
}
});
var gitMergetool= vscode.commands.registerCommand('extention.gitMergetool',function(){
var simpleGit = require('simple-git');
var projectPath = (vscode.workspace.rootPath)
simpleGit(projectPath).raw(
[
'mergetool'
], (err, result) => {
if(err)
vscode.window.showWarningMessage(err)
if(result.replace("\n","")=='No files need merging')
vscode.window.showInformationMessage("No files need merging");
console.log(result);
});
});
context.subscriptions.push(gitMergetool);
context.subscriptions.push(gitDiffer);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {}
exports.deactivate = deactivate;