Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Add amend commit feature #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/dialogs/commit-dialog.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ class CommitDialog extends Dialog
@button click: 'cancel', =>
@i class: 'icon x'
@span 'Cancel'
@input type: 'checkbox', id: 'amend', outlet: 'amendCheckbox'
@label 'Amend', for: 'amend'


activate: ->
super()
@msg.val('')
@msg.focus()
return

amend: ->
return @amendCheckbox.prop('checked')

resetAmend: ->
@amendCheckbox.prop('checked', false)

colorLength: ->
too_long = false
for line, i in @msg.val().split("\n")
Expand Down
4 changes: 3 additions & 1 deletion lib/git-control-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ class GitControlView extends View
return unless @filesView.hasSelected()

msg = @commitDialog.getMessage()
amend = @commitDialog.amend()
@commitDialog.resetAmend()

files = @filesView.getSelected()
@filesView.unselectAll()

git.add(files.add)
.then -> git.remove(files.rem)
.then -> git.commit(msg)
.then -> git.commit(msg, amend)
.then => @update()
return

Expand Down
5 changes: 3 additions & 2 deletions lib/git.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ module.exports =
atomRefresh()
return parseDefault(data)

commit: (message) ->
commit: (message, amend) ->
message = message or Date.now()
message = message.replace(/"/g, '\\"')
amendOpt = if amend then "--amend " else "--allow-empty-message"

return callGit "commit --allow-empty-message -m \"#{message}\"", (data) ->
return callGit "commit #{amendOpt} -m \"#{message}\"", (data) ->
atomRefresh()
return parseDefault(data)

Expand Down