@@ -5,23 +5,29 @@ var local = path.join.bind(path, __dirname);
55describe ( "Submodule" , function ( ) {
66 var NodeGit = require ( "../../" ) ;
77 var Repository = NodeGit . Repository ;
8+ var RepoUtils = require ( "../utils/repository_setup" ) ;
89 var Submodule = NodeGit . Submodule ;
910
10- var repoPath = local ( "../repos/workdir " ) ;
11+ var repoPath = local ( "../repos/submodule " ) ;
1112
1213 beforeEach ( function ( ) {
1314 var test = this ;
1415
15- return Repository . open ( repoPath )
16+ return RepoUtils . createRepository ( repoPath )
1617 . then ( function ( repo ) {
1718 test . repository = repo ;
1819 } ) ;
1920 } ) ;
2021
2122 it ( "can walk over the submodules" , function ( ) {
22- var repo = this . repository ;
23+ var repo ;
2324 var submoduleName = "vendor/libgit2" ;
24- return repo . getSubmoduleNames ( )
25+
26+ return Repository . open ( local ( "../repos/workdir" ) )
27+ . then ( function ( _repo ) {
28+ repo = _repo ;
29+ return repo . getSubmoduleNames ( ) ;
30+ } )
2531 . then ( function ( submodules ) {
2632 assert . equal ( submodules . length , 1 ) ;
2733
@@ -36,4 +42,54 @@ describe("Submodule", function() {
3642 assert . equal ( submodule . name ( ) , submoduleName ) ;
3743 } ) ;
3844 } ) ;
45+
46+ it ( "can setup and finalize submodule add" , function ( ) {
47+ var repo = this . repository ;
48+ var submodulePath = "hellogitworld" ;
49+ var submoduleUrl = "https://github.com/githubtraining/hellogitworld.git" ;
50+
51+ var submodule ;
52+ var submoduleRepo ;
53+
54+ return NodeGit . Submodule . addSetup ( repo , submoduleUrl , submodulePath , 0 )
55+ . then ( function ( _submodule ) {
56+ submodule = _submodule ;
57+
58+ return submodule . init ( 0 ) ;
59+ } )
60+ . then ( function ( ) {
61+ return submodule . open ( ) ;
62+ } )
63+ . then ( function ( _submoduleRepo ) {
64+ submoduleRepo = _submoduleRepo ;
65+ return submoduleRepo . fetch ( "origin" , null , null ) ;
66+ } )
67+ . then ( function ( ) {
68+ return submoduleRepo . getReference ( "origin/master" ) ;
69+ } )
70+ . then ( function ( reference ) {
71+ return reference . peel ( NodeGit . Object . TYPE . COMMIT ) ;
72+ } )
73+ . then ( function ( commit ) {
74+ return submoduleRepo . createBranch ( "master" , commit ) ;
75+ } )
76+ . then ( function ( ) {
77+ return submodule . addFinalize ( ) ;
78+ } )
79+ . then ( function ( ) {
80+ // check whether the submodule exists
81+ return Submodule . lookup ( repo , submodulePath ) ;
82+ } )
83+ . then ( function ( submodule ) {
84+ assert . equal ( submodule . name ( ) , submodulePath ) ;
85+ // check whether .gitmodules and the submodule are in the index
86+ return repo . openIndex ( ) ;
87+ } )
88+ . then ( function ( index ) {
89+ var entries = index . entries ( ) ;
90+ assert . equal ( entries . length , 2 ) ;
91+ assert . equal ( entries [ 0 ] . path , ".gitmodules" ) ;
92+ assert . equal ( entries [ 1 ] . path , submodulePath ) ;
93+ } ) ;
94+ } ) ;
3995} ) ;
0 commit comments