Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging support #44

Merged
merged 4 commits into from
Aug 5, 2022
Merged
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
24 changes: 16 additions & 8 deletions git_crecord/chunk_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,21 @@ def refresh(self):
signal.signal(signal.SIGTSTP, f)


_headermessages = {
header_messages = {
# {operation: text}
'crecord': _('Select hunks to commit'),
'cstage': _('Select hunks to stage'),
'cunstage': _('Select hunks to keep'),
}

_confirmmessages = {
main_operation_messages = {
# {operation: text}
'crecord': _('c: commit'),
'cstage': _('s: stage'),
'cunstage': None, # TODO: not implemented!
}

confirm_messages = {
'crecord': _('Are you sure you want to commit the selected changes [Yn]?'),
'cstage': _('Are you sure you want to stage the selected changes [Yn]?'),
'cunstage': _('Are you sure you want to unstage the unselected changes [Yn]?'),
Expand Down Expand Up @@ -583,10 +590,10 @@ def _getstatuslinesegments(self):
"""-> [str]. return segments"""
selected = self.currentselecteditem.applied
segments = [
_headermessages[self.opts['operation']],
header_messages[self.opts['operation']],
'-',
_('[x]=selected **=collapsed'),
_('c: confirm'),
main_operation_messages[self.opts['operation']],
_('q: abort'),
_('arrow keys: move/expand/collapse'),
_('space: deselect') if selected else _('space: select'),
Expand Down Expand Up @@ -1069,7 +1076,7 @@ def confirmcommit(self, review=False):
"""
)
else:
confirmtext = _confirmmessages[self.opts['operation']]
confirmtext = confirm_messages[self.opts['operation']]

response = self.confirmationwindow(confirmtext)

Expand Down Expand Up @@ -1135,13 +1142,14 @@ def handlekeypressed(self, keypressed):
elif keypressed in ['a']:
self.toggleamend()
elif keypressed in ["c"]:
self.opts['confirm'] |= self.opts['operation'] != 'crecord'
if self.confirmcommit():
self.opts['commit'] = True
self.opts['operation'] = 'crecord'
return True
elif keypressed in ["s"]:
self.opts['commit'] = False
self.opts['confirm'] |= self.opts['operation'] != 'cstage'
if self.confirmcommit():
self.opts['commit'] = False
self.opts['operation'] = 'cstage'
return True
elif keypressed in ["r"]:
if self.confirmcommit(review=True):
Expand Down
2 changes: 1 addition & 1 deletion git_crecord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def stage(self, *files, **opts):
to_add = [f for f in files if os.path.exists(f)]
if to_add:
system(
['git', 'add', '-f', '-N', '--'] + to_add,
['git', 'add', '-f', '--'] + to_add,
onerr=Abort,
errprefix=_("add failed"),
)
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ doctest_optionflags = NORMALIZE_WHITESPACE
[options.entry_points]
console_scripts =
git-crecord = git_crecord.main:main
git-cstage = git_crecord.main:main

[flake8]
doctests = yes
Expand Down