@@ -22,15 +22,29 @@ module.exports = class Git {
2222 return ( this . gitPath ? true : false ) ;
2323 }
2424
25+ /**
26+ * Execute command on remote system
27+ * @param {string } command
28+ * @returns {Promise<string> }
29+ */
30+ async paseCommand ( command ) {
31+ const execution = await vscode . commands . executeCommand ( `code-for-ibmi.runCommand` , {
32+ command,
33+ environment : `pase` ,
34+ cwd : this . path
35+ } ) ;
36+
37+ if ( execution . code === 0 || execution . code === null ) return Promise . resolve ( execution . stdout ) ;
38+ else return Promise . reject ( execution . stderr ) ;
39+ }
40+
2541 /**
2642 * Checks if the directory is a git repo
2743 * @returns {boolean }
2844 */
2945 async isGitRepo ( ) {
30- const connection = instance . getConnection ( ) ;
31-
3246 try {
33- const result = await connection . paseCommand ( `${ this . gitPath } rev-parse --is-inside-work-tree` , this . path ) ;
47+ const result = await this . paseCommand ( `${ this . gitPath } rev-parse --is-inside-work-tree` , this . path ) ;
3448 return true ;
3549 } catch ( e ) {
3650 return false ;
@@ -44,9 +58,7 @@ module.exports = class Git {
4458 * @returns {{hash: string, author: string, when: string, text: string}[] }
4559 */
4660 async getCommits ( count = 50 , file ) {
47- const connection = instance . getConnection ( ) ;
48-
49- const result = await connection . paseCommand ( `${ this . gitPath } --no-pager log --max-count=${ count } --pretty=format:"%h|%an|%ar|%s" ${ file ? ` -- ${ file } ` : `` } ` , this . path ) ;
61+ const result = await this . paseCommand ( `${ this . gitPath } --no-pager log --max-count=${ count } --pretty=format:"%h|%an|%ar|%s" ${ file ? ` -- ${ file } ` : `` } ` , this . path ) ;
5062
5163 //TODO: No changes message
5264 if ( result === `` ) return [ ] ;
@@ -74,9 +86,7 @@ module.exports = class Git {
7486 * @returns {{hash: string, path: string}[] }
7587 */
7688 async getChangesInCommit ( hash ) {
77- const connection = instance . getConnection ( ) ;
78-
79- const files = await connection . paseCommand (
89+ const files = await this . paseCommand (
8090 `${ this . gitPath } diff-tree --no-commit-id --name-only -r ${ hash } ` ,
8191 this . path ,
8292 ) ;
@@ -102,9 +112,7 @@ module.exports = class Git {
102112 * @returns {string }
103113 */
104114 async getFileContent ( hash , relativePath ) {
105- const connection = instance . getConnection ( ) ;
106-
107- const content = await connection . paseCommand (
115+ const content = await this . paseCommand (
108116 `${ this . gitPath } show ${ hash } :${ relativePath } ` ,
109117 this . path ,
110118 ) ;
@@ -116,11 +124,10 @@ module.exports = class Git {
116124 * @returns {{staged: {path, state}[], unstaged: {path, state}[]} }
117125 */
118126 async status ( ) {
119- const connection = instance . getConnection ( ) ;
120127 let staged = [ ] , unstaged = [ ] ;
121128
122129 let item = { path : `` , status : `` , state : [ ] } ;
123- let content = await connection . paseCommand (
130+ let content = await this . paseCommand (
124131 `echo '"' && ${ this . gitPath } status --short` ,
125132 this . path ,
126133 ) ;
@@ -155,9 +162,7 @@ module.exports = class Git {
155162 * @param {string } path
156163 */
157164 async stage ( path ) {
158- const connection = instance . getConnection ( ) ;
159-
160- await connection . paseCommand (
165+ await this . paseCommand (
161166 `${ this . gitPath } add ${ path } ` ,
162167 this . path ,
163168 ) ;
@@ -167,9 +172,7 @@ module.exports = class Git {
167172 * @param {string } path
168173 */
169174 async unstage ( path ) {
170- const connection = instance . getConnection ( ) ;
171-
172- await connection . paseCommand (
175+ await this . paseCommand (
173176 `${ this . gitPath } reset -- ${ path } ` ,
174177 this . path ,
175178 ) ;
@@ -179,9 +182,7 @@ module.exports = class Git {
179182 * @param {string } path
180183 */
181184 async restore ( path ) {
182- const connection = instance . getConnection ( ) ;
183-
184- await connection . paseCommand (
185+ await this . paseCommand (
185186 `${ this . gitPath } checkout -- ${ path } ` ,
186187 this . path ,
187188 ) ;
@@ -192,11 +193,9 @@ module.exports = class Git {
192193 * @param {string } message
193194 */
194195 async commit ( message ) {
195- const connection = instance . getConnection ( ) ;
196-
197196 message = message . replace ( new RegExp ( `"` , `g` ) , `\\"` ) ;
198197
199- await connection . paseCommand (
198+ await this . paseCommand (
200199 `${ this . gitPath } commit -m "${ message } "` ,
201200 this . path ,
202201 ) ;
@@ -206,10 +205,9 @@ module.exports = class Git {
206205 * Push commits
207206 */
208207 async push ( ) {
209- const connection = instance . getConnection ( ) ;
210208 const branch = await this . getCurrentBranch ( ) ;
211209
212- await connection . paseCommand (
210+ await this . paseCommand (
213211 `${ this . gitPath } push ${ branch ? `origin ${ branch } ` : `` } ` . trim ( ) ,
214212 this . path ,
215213 ) ;
@@ -219,9 +217,7 @@ module.exports = class Git {
219217 * Pull commits
220218 */
221219 async pull ( ) {
222- const connection = instance . getConnection ( ) ;
223-
224- await connection . paseCommand (
220+ await this . paseCommand (
225221 `${ this . gitPath } pull` ,
226222 this . path ,
227223 ) ;
@@ -235,7 +231,7 @@ module.exports = class Git {
235231 const connection = instance . getConnection ( ) ;
236232
237233 try {
238- const result = await connection . paseCommand ( `${ this . gitPath } rev-parse --abbrev-ref HEAD` , this . path ) ;
234+ const result = await this . paseCommand ( `${ this . gitPath } rev-parse --abbrev-ref HEAD` , this . path ) ;
239235 return result ;
240236 } catch ( e ) {
241237 return false ;
@@ -246,11 +242,10 @@ module.exports = class Git {
246242 * @returns {remote: branch_name[], local: {branch_name, state}[] }}
247243 */
248244 async listBranches ( ) {
249- const connection = instance . getConnection ( ) ;
250245 let remote = [ ] , local = [ ] ;
251246
252247 let item = { branch_name : `` , state : `` } ;
253- let content = await connection . paseCommand (
248+ let content = await this . paseCommand (
254249 `echo '"' && ${ this . gitPath } branch --all --list` ,
255250 this . path ,
256251 ) ;
@@ -282,8 +277,7 @@ module.exports = class Git {
282277 * @param {string } branchName Branch name to create
283278 */
284279 async createBranch ( branchName ) {
285- const connection = instance . getConnection ( ) ;
286- await connection . paseCommand (
280+ await this . paseCommand (
287281 `${ this . gitPath } branch "${ branchName } "` ,
288282 this . path ,
289283 ) ;
@@ -298,7 +292,6 @@ module.exports = class Git {
298292 let result = await vscode . window . showWarningMessage ( `Are you sure you want to delete branch ${ branchName } ?` , `Yes` , `Cancel` ) ;
299293
300294 if ( result === `Yes` ) {
301- const connection = instance . getConnection ( ) ;
302295 let command ;
303296
304297 if ( branchLocation === `remote` ) {
@@ -308,7 +301,7 @@ module.exports = class Git {
308301 command = `${ this . gitPath } branch -D "${ branchName } "` ;
309302 }
310303
311- await connection . paseCommand (
304+ await this . paseCommand (
312305 command ,
313306 this . path ,
314307 ) ;
@@ -321,8 +314,6 @@ module.exports = class Git {
321314 * @param {string } branchLocation
322315 */
323316 async checkout ( branchName , branchLocation ) {
324- const connection = instance . getConnection ( ) ;
325-
326317 let command ;
327318 if ( branchLocation === `remote` ) {
328319 const split_branch_name = branchName . split ( `/` ) ;
@@ -331,7 +322,7 @@ module.exports = class Git {
331322 command = `${ this . gitPath } checkout "${ branchName } "` ;
332323 }
333324
334- await connection . paseCommand (
325+ await this . paseCommand (
335326 command ,
336327 this . path ,
337328 ) ;
@@ -342,8 +333,7 @@ module.exports = class Git {
342333 * @param {string } branchName Branch to merge into current branch
343334 */
344335 async merge ( branchName ) {
345- const connection = instance . getConnection ( ) ;
346- await connection . paseCommand (
336+ await this . paseCommand (
347337 `${ this . gitPath } merge "${ branchName } "` ,
348338 this . path ,
349339 ) ;
0 commit comments