@@ -48,12 +48,42 @@ exports.tag = function(version, message, cwd, cb) {
4848 run_command ( 'git tag -a "' + version + '" -m "' + message + '"' , cwd , cb ) ;
4949} ;
5050
51- exports . checkout_branch = function ( branch_name , cwd , cb ) {
52- run_command ( 'git checkout -b ' + branch_name , cwd , cb ) ;
51+ exports . checkout_treeish = function ( treeish_name , cwd , cb ) {
52+ // See what branch we are on
53+ run_command ( 'git symbolic-ref --quiet --short HEAD' , cwd , function ( err , current_branch ) {
54+ if ( err ) {
55+ // If we are not on a branch, this will error out, but ignore it
56+ logger . debug ( 'Repo is not currently on a branch: %s' , cwd ) ;
57+ }
58+
59+ // If the selected name is the current branch, just check it out.
60+ if ( current_branch === treeish_name ) {
61+ // We are checking out the current branch, so just checkout.
62+ run_command ( 'git checkout ' + treeish_name , cwd , cb ) ;
63+ return ;
64+ }
65+
66+ // Assume that the checkout is not a branch (tree or hash) and try check it out
67+ run_command ( 'git checkout ' + treeish_name , cwd , function ( err , output ) {
68+ if ( err ) {
69+ logger . debug ( 'Could not checkout %s; creating branch' , treeish_name ) ;
70+ run_command ( 'git checkout -b ' + treeish_name , cwd , cb ) ;
71+ return ;
72+ }
73+ cb ( null , output ) ;
74+ } ) ;
75+ } ) ;
5376} ;
5477
55- exports . clone = function ( repo_url , branch_name , cwd , cb ) {
56- run_command ( 'git clone -b ' + branch_name + ' ' + repo_url + ' ' + branch_name , cwd , cb ) ;
78+ exports . clone = function ( repo_url , treeish_name , cwd , cb ) {
79+ run_command ( 'git clone -n ' + repo_url + ' ' + treeish_name , cwd , function ( err , output ) {
80+ if ( err ) {
81+ cb ( err ) ;
82+ return ;
83+ }
84+
85+ exports . checkout_treeish ( treeish_name , cwd + '/' + treeish_name , cb ) ;
86+ } ) ;
5787} ;
5888
5989exports . pull = function ( branch_name , cwd , cb ) {
@@ -122,8 +152,8 @@ exports.listAdditionalPropertyFiles = function(modifiedRecords, cwd, cb) {
122152
123153 function is_properties_not_modified ( modifiedRecords , file ) {
124154 return file . substr ( file . lastIndexOf ( '.' ) + 1 ) == "properties" && modifiedRecords . filter ( function ( record ) {
125- return record . path == file ;
126- } ) . length <= 0 ;
155+ return record . path == file ;
156+ } ) . length <= 0 ;
127157 }
128158
129159 run_command ( 'git ls-tree --name-status -r HEAD' , cwd , function ( err , output ) {
@@ -133,7 +163,7 @@ exports.listAdditionalPropertyFiles = function(modifiedRecords, cwd, cb) {
133163 var records = [ ] ;
134164 var files = output . split ( '\n' ) ;
135165 files . forEach ( function ( file ) {
136- if ( is_properties_not_modified ( modifiedRecords , file ) ) {
166+ if ( is_properties_not_modified ( modifiedRecords , file ) ) {
137167 records . push ( { 'type' : 'M' , 'path' : file } ) ;
138168 }
139169 } ) ;
0 commit comments