Skip to content

Commit 11f30ca

Browse files
author
Eugene Kalyada
committed
fix: (commit) Fix commit command
Fixed messages on validation Removed `-m` command
1 parent 58508f5 commit 11f30ca

File tree

3 files changed

+223
-44
lines changed

3 files changed

+223
-44
lines changed

gitcom.xcodeproj/xcuserdata/gener.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 205 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
ignoreCount = "0"
9191
continueAfterRunningActions = "No"
9292
filePath = "gitcom/Commands/IntegrateCommand.swift"
93-
timestampString = "574374870.899838"
93+
timestampString = "574422379.646386"
9494
startingColumnNumber = "9223372036854775807"
9595
endingColumnNumber = "9223372036854775807"
9696
startingLineNumber = "43"
@@ -106,7 +106,7 @@
106106
ignoreCount = "0"
107107
continueAfterRunningActions = "No"
108108
filePath = "gitcom/Commands/IntegrateCommand.swift"
109-
timestampString = "574374870.901197"
109+
timestampString = "574422379.6465369"
110110
startingColumnNumber = "9223372036854775807"
111111
endingColumnNumber = "9223372036854775807"
112112
startingLineNumber = "42"
@@ -122,7 +122,7 @@
122122
ignoreCount = "0"
123123
continueAfterRunningActions = "No"
124124
filePath = "gitcom/Commands/IntegrateCommand.swift"
125-
timestampString = "574374870.902341"
125+
timestampString = "574422379.646664"
126126
startingColumnNumber = "9223372036854775807"
127127
endingColumnNumber = "9223372036854775807"
128128
startingLineNumber = "53"
@@ -138,7 +138,7 @@
138138
ignoreCount = "0"
139139
continueAfterRunningActions = "No"
140140
filePath = "gitcom/Commands/IntegrateCommand.swift"
141-
timestampString = "574374870.903435"
141+
timestampString = "574422379.6467839"
142142
startingColumnNumber = "9223372036854775807"
143143
endingColumnNumber = "9223372036854775807"
144144
startingLineNumber = "46"
@@ -154,7 +154,7 @@
154154
ignoreCount = "0"
155155
continueAfterRunningActions = "No"
156156
filePath = "gitcom/Commands/IntegrateCommand.swift"
157-
timestampString = "574374870.9044811"
157+
timestampString = "574422379.6469001"
158158
startingColumnNumber = "9223372036854775807"
159159
endingColumnNumber = "9223372036854775807"
160160
startingLineNumber = "66"
@@ -170,7 +170,7 @@
170170
ignoreCount = "0"
171171
continueAfterRunningActions = "No"
172172
filePath = "gitcom/Commands/IntegrateCommand.swift"
173-
timestampString = "574374870.905466"
173+
timestampString = "574422379.646996"
174174
startingColumnNumber = "9223372036854775807"
175175
endingColumnNumber = "9223372036854775807"
176176
startingLineNumber = "72"
@@ -186,7 +186,7 @@
186186
ignoreCount = "0"
187187
continueAfterRunningActions = "No"
188188
filePath = "gitcom/Commands/IntegrateCommand.swift"
189-
timestampString = "574374870.906389"
189+
timestampString = "574422379.6470931"
190190
startingColumnNumber = "9223372036854775807"
191191
endingColumnNumber = "9223372036854775807"
192192
startingLineNumber = "50"
@@ -202,11 +202,11 @@
202202
ignoreCount = "0"
203203
continueAfterRunningActions = "No"
204204
filePath = "gitcom/Commands/CommitCommand.swift"
205-
timestampString = "574374870.9073499"
205+
timestampString = "574422379.647194"
206206
startingColumnNumber = "9223372036854775807"
207207
endingColumnNumber = "9223372036854775807"
208-
startingLineNumber = "216"
209-
endingLineNumber = "216"
208+
startingLineNumber = "213"
209+
endingLineNumber = "213"
210210
landmarkName = "perform(arguments:)"
211211
landmarkType = "7">
212212
</BreakpointContent>
@@ -218,14 +218,206 @@
218218
ignoreCount = "0"
219219
continueAfterRunningActions = "No"
220220
filePath = "gitcom/Commands/CommitCommand.swift"
221-
timestampString = "574374870.90741"
221+
timestampString = "574422379.6480319"
222222
startingColumnNumber = "9223372036854775807"
223223
endingColumnNumber = "9223372036854775807"
224-
startingLineNumber = "214"
225-
endingLineNumber = "214"
224+
startingLineNumber = "211"
225+
endingLineNumber = "211"
226226
landmarkName = "perform(arguments:)"
227227
landmarkType = "7">
228228
</BreakpointContent>
229229
</BreakpointProxy>
230+
<BreakpointProxy
231+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
232+
<BreakpointContent
233+
shouldBeEnabled = "No"
234+
ignoreCount = "0"
235+
continueAfterRunningActions = "No"
236+
filePath = "gitcom/Commands/ValidateCommand.swift"
237+
timestampString = "574422379.648683"
238+
startingColumnNumber = "9223372036854775807"
239+
endingColumnNumber = "9223372036854775807"
240+
startingLineNumber = "28"
241+
endingLineNumber = "28"
242+
landmarkName = "checkType(header:subject:)"
243+
landmarkType = "7">
244+
</BreakpointContent>
245+
</BreakpointProxy>
246+
<BreakpointProxy
247+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
248+
<BreakpointContent
249+
shouldBeEnabled = "No"
250+
ignoreCount = "0"
251+
continueAfterRunningActions = "No"
252+
filePath = "gitcom/Commands/ValidateCommand.swift"
253+
timestampString = "574422379.649097"
254+
startingColumnNumber = "9223372036854775807"
255+
endingColumnNumber = "9223372036854775807"
256+
startingLineNumber = "41"
257+
endingLineNumber = "41"
258+
landmarkName = "checkScope(header:subject:type:)"
259+
landmarkType = "7">
260+
</BreakpointContent>
261+
</BreakpointProxy>
262+
<BreakpointProxy
263+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
264+
<BreakpointContent
265+
shouldBeEnabled = "No"
266+
ignoreCount = "0"
267+
continueAfterRunningActions = "No"
268+
filePath = "gitcom/Commands/ValidateCommand.swift"
269+
timestampString = "574422379.6494451"
270+
startingColumnNumber = "9223372036854775807"
271+
endingColumnNumber = "9223372036854775807"
272+
startingLineNumber = "89"
273+
endingLineNumber = "89"
274+
landmarkName = "checkHeaderLength(header:subject:type:scope:)"
275+
landmarkType = "7">
276+
</BreakpointContent>
277+
</BreakpointProxy>
278+
<BreakpointProxy
279+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
280+
<BreakpointContent
281+
shouldBeEnabled = "No"
282+
ignoreCount = "0"
283+
continueAfterRunningActions = "No"
284+
filePath = "gitcom/Helpers.swift"
285+
timestampString = "574422379.649797"
286+
startingColumnNumber = "9223372036854775807"
287+
endingColumnNumber = "9223372036854775807"
288+
startingLineNumber = "38"
289+
endingLineNumber = "38"
290+
landmarkName = "stringByReplacingFirstOccurrenceOfString(target:withString:)"
291+
landmarkType = "7">
292+
</BreakpointContent>
293+
</BreakpointProxy>
294+
<BreakpointProxy
295+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
296+
<BreakpointContent
297+
shouldBeEnabled = "No"
298+
ignoreCount = "0"
299+
continueAfterRunningActions = "No"
300+
filePath = "gitcom/Commands/ValidateCommand.swift"
301+
timestampString = "574422379.649859"
302+
startingColumnNumber = "9223372036854775807"
303+
endingColumnNumber = "9223372036854775807"
304+
startingLineNumber = "179"
305+
endingLineNumber = "179"
306+
landmarkName = "validate(config:parts:)"
307+
landmarkType = "7">
308+
<Locations>
309+
<Location
310+
shouldBeEnabled = "No"
311+
ignoreCount = "0"
312+
continueAfterRunningActions = "No"
313+
symbolName = "gitcom.ValidateCommand.(validate in _D418C0935C7D14171029779C7EADEF76)(config: gitcom.CommitConfig, parts: Swift.Array&lt;Swift.Substring&gt;) -&gt; Swift.Bool"
314+
moduleName = "gitcom"
315+
usesParentBreakpointCondition = "Yes"
316+
urlString = "file:///Users/gener/Documents/Projects/swift/gitcmt/gitcom/Commands/ValidateCommand.swift"
317+
timestampString = "574420419.218551"
318+
startingColumnNumber = "9223372036854775807"
319+
endingColumnNumber = "9223372036854775807"
320+
startingLineNumber = "171"
321+
endingLineNumber = "171"
322+
offsetFromSymbolStart = "107">
323+
</Location>
324+
<Location
325+
shouldBeEnabled = "No"
326+
ignoreCount = "0"
327+
continueAfterRunningActions = "No"
328+
symbolName = "closure #1 (Swift.Substring) -&gt; Swift.String in gitcom.ValidateCommand.(validate in _D418C0935C7D14171029779C7EADEF76)(config: gitcom.CommitConfig, parts: Swift.Array&lt;Swift.Substring&gt;) -&gt; Swift.Bool"
329+
moduleName = "gitcom"
330+
usesParentBreakpointCondition = "Yes"
331+
urlString = "file:///Users/gener/Documents/Projects/swift/gitcmt/gitcom/Commands/ValidateCommand.swift"
332+
timestampString = "574420419.221997"
333+
startingColumnNumber = "9223372036854775807"
334+
endingColumnNumber = "9223372036854775807"
335+
startingLineNumber = "171"
336+
endingLineNumber = "171"
337+
offsetFromSymbolStart = "20">
338+
</Location>
339+
</Locations>
340+
</BreakpointContent>
341+
</BreakpointProxy>
342+
<BreakpointProxy
343+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
344+
<BreakpointContent
345+
shouldBeEnabled = "No"
346+
ignoreCount = "0"
347+
continueAfterRunningActions = "No"
348+
filePath = "gitcom/Commands/ValidateCommand.swift"
349+
timestampString = "574422379.650212"
350+
startingColumnNumber = "9223372036854775807"
351+
endingColumnNumber = "9223372036854775807"
352+
startingLineNumber = "180"
353+
endingLineNumber = "180"
354+
landmarkName = "validate(config:parts:)"
355+
landmarkType = "7">
356+
</BreakpointContent>
357+
</BreakpointProxy>
358+
<BreakpointProxy
359+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
360+
<BreakpointContent
361+
shouldBeEnabled = "No"
362+
ignoreCount = "0"
363+
continueAfterRunningActions = "No"
364+
filePath = "gitcom/Commands/ValidateCommand.swift"
365+
timestampString = "574422379.650538"
366+
startingColumnNumber = "9223372036854775807"
367+
endingColumnNumber = "9223372036854775807"
368+
startingLineNumber = "185"
369+
endingLineNumber = "185"
370+
landmarkName = "validate(config:parts:)"
371+
landmarkType = "7">
372+
</BreakpointContent>
373+
</BreakpointProxy>
374+
<BreakpointProxy
375+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
376+
<BreakpointContent
377+
shouldBeEnabled = "No"
378+
ignoreCount = "0"
379+
continueAfterRunningActions = "No"
380+
filePath = "gitcom/Commands/ValidateCommand.swift"
381+
timestampString = "574422379.650866"
382+
startingColumnNumber = "9223372036854775807"
383+
endingColumnNumber = "9223372036854775807"
384+
startingLineNumber = "193"
385+
endingLineNumber = "193"
386+
landmarkName = "validate(config:parts:)"
387+
landmarkType = "7">
388+
</BreakpointContent>
389+
</BreakpointProxy>
390+
<BreakpointProxy
391+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
392+
<BreakpointContent
393+
shouldBeEnabled = "Yes"
394+
ignoreCount = "0"
395+
continueAfterRunningActions = "No"
396+
filePath = "gitcom/Commands/CheckConfigCommand.swift"
397+
timestampString = "574421600.325236"
398+
startingColumnNumber = "9223372036854775807"
399+
endingColumnNumber = "9223372036854775807"
400+
startingLineNumber = "31"
401+
endingLineNumber = "31"
402+
landmarkName = "config(path:)"
403+
landmarkType = "7">
404+
</BreakpointContent>
405+
</BreakpointProxy>
406+
<BreakpointProxy
407+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
408+
<BreakpointContent
409+
shouldBeEnabled = "No"
410+
ignoreCount = "0"
411+
continueAfterRunningActions = "No"
412+
filePath = "gitcom/Commands/CommitCommand.swift"
413+
timestampString = "574422379.651216"
414+
startingColumnNumber = "9223372036854775807"
415+
endingColumnNumber = "9223372036854775807"
416+
startingLineNumber = "21"
417+
endingLineNumber = "21"
418+
landmarkName = "hasStage"
419+
landmarkType = "24">
420+
</BreakpointContent>
421+
</BreakpointProxy>
230422
</Breakpoints>
231423
</Bucket>

gitcom/Commands/CommitCommand.swift

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ class CommitCommand: CommandProtocol {
1313

1414
var description: String = """
1515
Make beautiful commit.
16-
Add argument -m for inline message.
17-
'|' stand for new line symbol.
18-
Example: gitcom make -m "Type: (Scope) Subject|Body|FooterPrefix: Footer"
1916
"""
2017

2118
private let git = GitProcess()
2219

2320
private var hasStage: Bool {
24-
let res = git.run(arguments: ["status", "-uno", "-s"])
21+
let res = git.run(arguments: ["diff", "--cached", "--name-only"])
2522
switch res {
2623
case let .success(string):
2724
return string.count > 0
@@ -83,12 +80,12 @@ Example: gitcom make -m "Type: (Scope) Subject|Body|FooterPrefix: Footer"
8380
if input == header.customScope.back {
8481
return take(header: header)
8582
}
86-
if let min = header.customScope.length.min, min.value > input.count {
87-
print(error: min.message)
83+
if let min = header.customScope.length?.min, min.value > input.count {
84+
print(error: min.insufficient(prefix: "Scope"))
8885
return takeCustomScope(header: header)
8986
}
90-
if let max = header.customScope.length.max, max.value < input.count {
91-
print(error: max.message)
87+
if let max = header.customScope.length?.max, max.value < input.count {
88+
print(error: max.excess(prefix: "Scope"))
9289
return takeCustomScope(header: header)
9390
}
9491
return input
@@ -100,11 +97,11 @@ Example: gitcom make -m "Type: (Scope) Subject|Body|FooterPrefix: Footer"
10097
return takeSubject(header: header)
10198
}
10299
if let min = header.length.min, min.value > input.count {
103-
print(error: min.message)
100+
print(error: min.insufficient(prefix: "Subject"))
104101
return takeSubject(header: header)
105102
}
106103
if let max = header.length.max, max.value < input.count {
107-
print(error: max.message)
104+
print(error: max.excess(prefix: "Subject"))
108105
return takeSubject(header: header)
109106
}
110107
return input
@@ -138,11 +135,11 @@ Example: gitcom make -m "Type: (Scope) Subject|Body|FooterPrefix: Footer"
138135
return take(body: body)
139136
}
140137
if let min = body.length.min, min.value > input.count {
141-
print(error: min.message)
138+
print(error: min.insufficient(prefix: "Body"))
142139
return take(body: body)
143140
}
144141
if let max = body.length.max, max.value < input.count {
145-
print(error: max.message)
142+
print(error: max.excess(prefix: "Body"))
146143
return take(body: body)
147144
}
148145
return input.replacingOccurrences(of: body.newLineSpacer, with: "\n")
@@ -157,11 +154,11 @@ Example: gitcom make -m "Type: (Scope) Subject|Body|FooterPrefix: Footer"
157154
return take(footer: footer)
158155
}
159156
if let min = footer.length.min, min.value > input.count {
160-
print(error: min.message)
157+
print(error: min.insufficient(prefix: "Footer"))
161158
return take(footer: footer)
162159
}
163160
if let max = footer.length.max, max.value < input.count {
164-
print(error: max.message)
161+
print(error: max.excess(prefix: "Footer"))
165162
return take(footer: footer)
166163
}
167164
return input.count > 0 ? "\(footer.prefix) \(input)" : nil
@@ -213,22 +210,15 @@ Example: gitcom make -m "Type: (Scope) Subject|Body|FooterPrefix: Footer"
213210

214211
switch configCommand.config() {
215212
case let .success(config):
216-
if let firstArgument = arguments.first, firstArgument == Constants.messageArgument, arguments[safe: 1] == "-m", let message = arguments[safe: 2] {
217-
let validationCommand = ValidateCommand()
218-
validationCommand.delegate = self
219-
validationCommand.perform(arguments: [message])
213+
var message = ""
214+
message += self.take(header: config.header)
215+
if let body = self.take(body: config.body) {
216+
message.append("\n\(body)")
220217
}
221-
else {
222-
var message = ""
223-
message += self.take(header: config.header)
224-
if let body = self.take(body: config.body) {
225-
message.append("\n\(body)")
226-
}
227-
if let footer = self.take(footer: config.footer) {
228-
message.append("\n\(footer)")
229-
}
230-
makeCommit(message: message)
218+
if let footer = self.take(footer: config.footer) {
219+
message.append("\n\(footer)")
231220
}
221+
makeCommit(message: message)
232222
case let .failure(error):
233223
print(error: "Config file is invalid.")
234224
print(error: error)

0 commit comments

Comments
 (0)