@@ -42,16 +42,53 @@ define(function (require, exports, module) {
4242 function GitHubManager ( ) {
4343 }
4444
45- GitHubManager . prototype . writeTree = function ( tree , FileSystem ) {
45+ GitHubManager . prototype . targetPath = "" ;
46+
47+ GitHubManager . prototype . writeTree = function ( branch , tree , directory , progressCallback ) {
48+ var i = 0 ;
49+ console . log ( tree ) ;
50+ function writer ( contents ) {
51+ var file = FileSystem . getFileForPath ( directory . _path + this . path ) ;
52+
53+ file . write ( contents ) ;
54+
55+ progressCallback ( ) ;
56+ }
57+
58+ function writeDir ( path ) {
59+ var dir = FileSystem . getDirectoryForPath ( path ) ;
60+
61+ dir . create ( ) ;
62+
63+ progressCallback ( ) ;
64+ }
4665
66+ for ( i = 0 ; i < tree . length ; i ++ ) {
67+ if ( tree [ i ] . type === "blob" ) {
68+ branch . contents ( tree [ i ] . path ) . then ( $ . proxy ( writer , tree [ i ] ) , function ( ) {
69+ console . log ( arguments ) ;
70+ } ) ;
71+ } else {
72+ writeDir ( directory . _path + tree [ i ] . path ) ;
73+ }
74+ }
4775 } ;
4876
49- GitHubManager . prototype . cloneRepo = function ( repo , branch , targetPath ) {
50- repo . git . getTree ( "master" , {
77+ GitHubManager . prototype . cloneRepo = function ( repo , branch ) {
78+ repo . git . getTree ( branch , {
5179 recursive : true
52- } ) . then ( function ( tree ) {
53- console . log ( tree ) ;
54- } ) ;
80+ } ) . then ( $ . proxy ( function ( tree ) {
81+ console . log ( this . targetPath ) ;
82+
83+ var length = tree . length ,
84+ i = 0 ,
85+ dir = FileSystem . getDirectoryForPath ( this . targetPath ) ;
86+
87+ this . writeTree ( repo . getBranch ( branch ) , tree , dir , function ( ) {
88+ i ++ ;
89+ console . log ( ( i / length ) * 100 + "%" ) ;
90+ } ) ;
91+ } , this ) ) ;
5592 } ;
5693
5794 GitHubManager . prototype . addSelectMenueForArray = function ( $element , array ) {
@@ -139,16 +176,17 @@ define(function (require, exports, module) {
139176 if ( id === "cancel" ) {
140177 Dialogs . cancelModalDialogIfOpen ( "github-access" , "cancel" ) ;
141178 } else if ( id === "clone" ) {
142- self . cloneRepo ( repo , $dlg . find ( ".branch-selection" ) . val ( ) , $dlg . find ( "div.step1" ) . find ( "input" ) . val ( ) ) ;
179+ self . targetPath = $dlg . find ( "div.step1" ) . find ( "input.target-path" ) . val ( ) ;
180+ self . cloneRepo ( repo , $dlg . find ( ".branch-selection" ) . val ( ) ) ;
143181 Dialogs . cancelModalDialogIfOpen ( "github-access" , "clone" ) ;
144182 }
145183 } ) ;
146184 } ;
147185
148186 GitHubManager . prototype . checkLoginData = function ( $element ) {
149- //TODO: Actual validity checking
187+ var valid = ( $element . find ( "input.oauth-token" ) . val ( ) . trim ( ) . length === 40 ) ;
150188
151- return true ;
189+ return valid ;
152190 } ;
153191
154192 GitHubManager . prototype . init = function ( ) {
0 commit comments