1- const SvnSpawn = require ( "svn-spawn" ) ;
21const vscode = require ( "vscode" ) ;
32const cp = require ( "child_process" ) ;
43const iconv = require ( "iconv-lite" ) ;
54
6- function svn ( cwd = null ) {
7- this . client = new SvnSpawn ( {
8- noAuthCache : true ,
9- cwd : cwd
10- } ) ;
11- this . canRun = true ;
12-
5+ function svn ( ) {
136 this . isSVNAvailable ( ) . catch ( ( ) => {
14- this . canRun = false ;
157 vscode . window . showErrorMessage (
168 "SVN is not available in your PATH. svn-scm is unable to run!"
179 ) ;
@@ -20,22 +12,33 @@ function svn(cwd = null) {
2012
2113svn . prototype . exec = function ( cwd , args , options = { } ) {
2214 return new Promise ( ( resolve , reject ) => {
23- options . cwd = cwd ;
15+ if ( cwd ) {
16+ options . cwd = cwd ;
17+ }
2418 const result = cp . spawn ( "svn" , args , options ) ;
25- let buffers = [ ] ;
19+ let outBuffers = [ ] ;
20+ let errBuffers = [ ] ;
2621
2722 result . stdout . on ( "data" , b => {
28- buffers . push ( b ) ;
23+ outBuffers . push ( b ) ;
2924 } ) ;
30- result . stderr . on ( "data" , data => {
31- reject ( ) ;
25+ result . stderr . on ( "data" , b => {
26+ errBuffers . push ( b ) ;
3227 } ) ;
3328 result . on ( "error" , data => {
3429 reject ( ) ;
3530 } ) ;
3631 result . on ( "close" , ( ) => {
37- resolve (
38- Buffer . concat ( buffers )
32+ if ( outBuffers . length > 0 ) {
33+ resolve (
34+ Buffer . concat ( outBuffers )
35+ . toString ( )
36+ . trim ( )
37+ ) ;
38+ }
39+
40+ reject (
41+ Buffer . concat ( errBuffers )
3942 . toString ( )
4043 . trim ( )
4144 ) ;
@@ -45,10 +48,10 @@ svn.prototype.exec = function(cwd, args, options = {}) {
4548
4649svn . prototype . getRepositoryRoot = async function ( path ) {
4750 try {
48- let result = await this . cmd ( [ "info" , path , "--show-item" , "wc-root" ] ) ;
51+ let result = await this . exec ( path , [ "info" , "--show-item" , "wc-root" ] ) ;
4952 return result ;
5053 } catch ( error ) {
51- throw new Error ( "Not a SVN repo" ) ;
54+ throw new Error ( "not a SVN repo" ) ;
5255 }
5356} ;
5457
@@ -68,34 +71,17 @@ svn.prototype.open = function(repositoryRoot, workspaceRoot) {
6871 return new Repository ( this , repositoryRoot , workspaceRoot ) ;
6972} ;
7073
71- svn . prototype . cmd = function ( args ) {
72- return new Promise ( ( resolve , reject ) => {
73- this . client . cmd ( args , ( err , data ) => ( err ? reject ( err ) : resolve ( data ) ) ) ;
74- } ) ;
74+ svn . prototype . add = function ( filePath ) {
75+ filePath = filePath . replace ( / \\ / g, "/" ) ;
76+ return this . exec ( "" , [ "add" , filePath ] ) ;
7577} ;
7678
77- svn . prototype . getStatus = function ( ) {
78- return new Promise ( ( resolve , reject ) => {
79- this . client . getStatus ( ( err , data ) => ( err ? reject ( err ) : resolve ( data ) ) ) ;
80- } ) ;
79+ svn . prototype . show = async function ( filePath ) {
80+ return this . exec ( "" , [ "cat" , "-r" , "HEAD" , filePath ] ) ;
8181} ;
8282
83- svn . prototype . commit = function ( params ) {
84- return new Promise ( ( resolve , reject ) => {
85- this . client . commit (
86- params ,
87- ( err , data ) => ( err ? reject ( err ) : resolve ( data ) )
88- ) ;
89- } ) ;
90- } ;
91-
92- svn . prototype . add = function ( filePath ) {
93- return new Promise ( ( resolve , reject ) => {
94- this . client . add (
95- filePath ,
96- ( err , data ) => ( err ? reject ( err ) : resolve ( data ) )
97- ) ;
98- } ) ;
83+ svn . prototype . list = async function ( filePath ) {
84+ return this . exec ( "" , [ "ls" , filePath ] ) ;
9985} ;
10086
10187module . exports = svn ;
@@ -104,11 +90,6 @@ function Repository(svn, repositoryRoot, workspaceRoot) {
10490 this . svn = svn ;
10591 this . root = repositoryRoot ;
10692 this . workspaceRoot = workspaceRoot ;
107-
108- this . svn . client . option ( {
109- cwd : this . workspaceRoot ,
110- noAuthCache : true
111- } ) ;
11293}
11394
11495Repository . prototype . getStatus = function ( ) {
@@ -135,3 +116,12 @@ Repository.prototype.getStatus = function() {
135116 } ) ;
136117 } ) ;
137118} ;
119+
120+ Repository . prototype . commit = async function ( message ) {
121+ try {
122+ let result = await this . svn . exec ( this . root , [ "commit" , "-m" , message ] ) ;
123+ return result ;
124+ } catch ( error ) {
125+ throw new Error ( "unable to commit files" ) ;
126+ }
127+ } ;
0 commit comments