@@ -55,45 +55,66 @@ describe('CommitController', function() {
55
55
atomEnvironment . destroy ( ) ;
56
56
} ) ;
57
57
58
+ describe ( 'when commit.template config is set' , function ( ) {
59
+ it ( 'populates the commit message with the template' , async function ( ) {
60
+ const workdirPath = await cloneRepository ( 'commit-template' ) ;
61
+ const repository = await buildRepository ( workdirPath ) ;
62
+ const templateCommitMessage = await repository . git . getCommitMessageFromTemplate ( ) ;
63
+ app = React . cloneElement ( app , { repository} ) ;
64
+ const wrapper = shallow ( app , { disableLifecycleMethods : true } ) ;
65
+ await assert . async . strictEqual ( wrapper . instance ( ) . getCommitMessage ( ) , templateCommitMessage ) ;
66
+ } ) ;
67
+
68
+ it ( 'restores template after committig' , async function ( ) {
69
+ const templateText = 'some commit message' ;
70
+ const commitMsgTemplatePath = path . join ( workdirPath , '.gitmessage' ) ;
71
+ await fs . writeFile ( commitMsgTemplatePath , templateText , { encoding : 'utf8' } ) ;
72
+ await repository . git . setConfig ( 'commit.template' , commitMsgTemplatePath ) ;
73
+
74
+ await fs . writeFile ( path . join ( workdirPath , 'a.txt' ) , 'some changes' , { encoding : 'utf8' } ) ;
75
+ await repository . git . exec ( [ 'add' , '.' ] ) ;
76
+
77
+ const wrapper = shallow ( app , { disableLifecycleMethods : true } ) ;
78
+ await wrapper . instance ( ) . commit ( 'some message' ) ;
79
+ assert . strictEqual ( repository . getCommitMessage ( ) , templateText ) ;
80
+ } ) ;
81
+ } ) ;
82
+
58
83
it ( 'correctly updates state when switching repos' , async function ( ) {
59
84
const workdirPath1 = await cloneRepository ( 'three-files' ) ;
60
85
const repository1 = await buildRepository ( workdirPath1 ) ;
61
86
const workdirPath2 = await cloneRepository ( 'three-files' ) ;
62
87
const repository2 = await buildRepository ( workdirPath2 ) ;
63
- const workdirPath3 = await cloneRepository ( 'commit-template' ) ;
64
- const repository3 = await buildRepository ( workdirPath3 ) ;
65
- const templateCommitMessage = await repository3 . git . getCommitMessageFromTemplate ( ) ;
88
+
89
+ // set commit template for repository2
90
+ const templateText = 'some commit message' ;
91
+ const commitMsgTemplatePath = path . join ( workdirPath2 , '.gitmessage' ) ;
92
+ await fs . writeFile ( commitMsgTemplatePath , templateText , { encoding : 'utf8' } ) ;
93
+ await repository2 . git . setConfig ( 'commit.template' , commitMsgTemplatePath ) ;
94
+ // assert.strictEqual(await repository2.getCommitMessageFromTemplate(), templateText);
95
+
96
+ // const workdirPath3 = await cloneRepository('commit-template');
97
+ // const repository3 = await buildRepository(workdirPath3);
98
+ // const templateCommitMessage = await repository3.git.getCommitMessageFromTemplate();
66
99
67
100
app = React . cloneElement ( app , { repository : repository1 } ) ;
68
101
const wrapper = shallow ( app , { disableLifecycleMethods : true } ) ;
69
102
70
103
assert . strictEqual ( wrapper . instance ( ) . getCommitMessage ( ) , '' ) ;
71
104
72
105
wrapper . instance ( ) . setCommitMessage ( 'message 1' ) ;
106
+ assert . equal ( wrapper . instance ( ) . getCommitMessage ( ) , 'message 1' ) ;
73
107
74
108
wrapper . setProps ( { repository : repository2 } ) ;
75
-
76
- assert . strictEqual ( wrapper . instance ( ) . getCommitMessage ( ) , '' ) ;
109
+ await assert . async . strictEqual ( wrapper . instance ( ) . getCommitMessage ( ) , templateText ) ;
77
110
78
111
wrapper . setProps ( { repository : repository1 } ) ;
79
112
assert . equal ( wrapper . instance ( ) . getCommitMessage ( ) , 'message 1' ) ;
80
- wrapper . setProps ( { repository : repository3 } ) ;
81
- await assert . async . strictEqual ( wrapper . instance ( ) . getCommitMessage ( ) , templateCommitMessage ) ;
82
- } ) ;
83
-
84
113
85
- describe ( 'when commit.template config is set' , function ( ) {
86
- it ( 'populates the commit message with the template' , async function ( ) {
87
- const workdirPath = await cloneRepository ( 'commit-template' ) ;
88
- const repository = await buildRepository ( workdirPath ) ;
89
- const templateCommitMessage = await repository . git . getCommitMessageFromTemplate ( ) ;
90
- app = React . cloneElement ( app , { repository} ) ;
91
- const wrapper = shallow ( app , { disableLifecycleMethods : true } ) ;
92
- await assert . async . strictEqual ( wrapper . instance ( ) . getCommitMessage ( ) , templateCommitMessage ) ;
93
- } ) ;
114
+ // wrapper.setProps({repository: repository3});
115
+ // await assert.async.strictEqual(wrapper.instance().getCommitMessage(), templateCommitMessage);
94
116
} ) ;
95
117
96
-
97
118
describe ( 'the passed commit message' , function ( ) {
98
119
let repository ;
99
120
@@ -158,21 +179,6 @@ describe('CommitController', function() {
158
179
assert . strictEqual ( repository . getCommitMessage ( ) , '' ) ;
159
180
} ) ;
160
181
161
- it ( 'reload the commit messages from commit template' , async function ( ) {
162
- const repoPath = await cloneRepository ( 'commit-template' ) ;
163
- const repo = await buildRepositoryWithPipeline ( repoPath , { confirm, notificationManager, workspace} ) ;
164
- const templateCommitMessage = await repo . git . getCommitMessageFromTemplate ( ) ;
165
- const commitStub = sinon . stub ( ) . callsFake ( ( ...args ) => repo . commit ( ...args ) ) ;
166
- const app2 = React . cloneElement ( app , { repository : repo , commit : commitStub } ) ;
167
-
168
- await fs . writeFile ( path . join ( repoPath , 'a.txt' ) , 'some changes' , { encoding : 'utf8' } ) ;
169
- await repo . git . exec ( [ 'add' , '.' ] ) ;
170
-
171
- const wrapper = shallow ( app2 , { disableLifecycleMethods : true } ) ;
172
- await wrapper . instance ( ) . commit ( 'some message' ) ;
173
- assert . strictEqual ( repo . getCommitMessage ( ) , templateCommitMessage ) ;
174
- } ) ;
175
-
176
182
it ( 'sets the verbatim flag when committing from the mini editor' , async function ( ) {
177
183
await fs . writeFile ( path . join ( workdirPath , 'a.txt' ) , 'some changes' , { encoding : 'utf8' } ) ;
178
184
await repository . git . exec ( [ 'add' , '.' ] ) ;
0 commit comments