Skip to content

Commit

Permalink
widgets: #1000 allow adding to local exclusions
Browse files Browse the repository at this point in the history
Rename status widget entry to `Ignore...`
Add a radio choice between committed .gitignore and local exclusion file

Signed-off-by: Benjamin Somers <benjamin.somers@telecom-bretagne.eu>
  • Loading branch information
bensmrs committed Nov 7, 2019
1 parent 4cf9ac2 commit d66eda6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
18 changes: 12 additions & 6 deletions cola/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,22 +600,28 @@ def do(self):


class Ignore(ContextCommand):
"""Add files to .gitignore"""
"""Add files to an exclusion file"""

def __init__(self, context, filenames):
def __init__(self, context, filenames, local=False):
super(Ignore, self).__init__(context)
self.filenames = list(filenames)
self.local = local

def do(self):
if not self.filenames:
return
new_additions = '\n'.join(self.filenames) + '\n'
for_status = new_additions
if core.exists('.gitignore'):
current_list = core.read('.gitignore')
if self.local:
filename = os.path.join('.git', 'info', 'exclude')
else:
filename = '.gitignore'
if core.exists(filename):
current_list = core.read(filename)
new_additions = current_list.rstrip() + '\n' + new_additions
core.write('.gitignore', new_additions)
Interaction.log_status(0, 'Added to .gitignore:\n%s' % for_status, '')
core.write(filename, new_additions)
Interaction.log_status(0, 'Added to %s:\n%s' % (filename, for_status),
'')
self.model.update_file_status()


Expand Down
27 changes: 21 additions & 6 deletions cola/widgets/gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, context, parent=None):
self.selection = context.selection
if parent is not None:
self.setWindowModality(QtCore.Qt.WindowModal)
self.setWindowTitle(N_('Add to .gitignore'))
self.setWindowTitle(N_('Add to exclusions'))

# Create text
self.text_description = QtWidgets.QLabel()
Expand All @@ -45,9 +45,21 @@ def __init__(self, context, parent=None):
self.radio_filename = qtutils.radio(text=N_('Ignore exact filename'),
checked=True)
self.radio_pattern = qtutils.radio(text=N_('Ignore custom pattern'))

self.radio_layt = qtutils.vbox(defs.no_margin, defs.spacing,
self.radio_filename, self.radio_pattern)
self.name_radio_group = qtutils.buttongroup(self.radio_filename,
self.radio_pattern)
self.name_radio_layt = qtutils.vbox(defs.no_margin, defs.spacing,
self.radio_filename,
self.radio_pattern)

self.radio_in_repo = qtutils.radio(text=N_('Add to .gitignore'),
checked=True)
self.radio_local = qtutils.radio(text=N_('Add to local '
'.git/info/exclude'))
self.location_radio_group = qtutils.buttongroup(self.radio_in_repo,
self.radio_local)
self.location_radio_layt = qtutils.vbox(defs.no_margin, defs.spacing,
self.radio_in_repo,
self.radio_local)

# Create buttons
self.button_apply = qtutils.ok_button(text=N_('Add'))
Expand All @@ -59,9 +71,11 @@ def __init__(self, context, parent=None):

# Layout
self.main_layout = qtutils.vbox(defs.margin, defs.spacing,
self.radio_layt,
self.name_radio_layt,
defs.button_spacing,
self.filename_layt,
defs.button_spacing,
self.location_radio_layt,
qtutils.STRETCH,
self.btn_layt)
self.setLayout(self.main_layout)
Expand Down Expand Up @@ -91,5 +105,6 @@ def close(self):

def apply(self):
context = self.context
cmds.do(cmds.Ignore, context, self.edit_filename.text().split(';'))
cmds.do(cmds.Ignore, context, self.edit_filename.text().split(';'),
self.radio_local.isChecked())
self.accept()
2 changes: 1 addition & 1 deletion cola/widgets/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def _create_unstaged_context_menu(self, menu, s):
menu.addAction(self.move_to_trash_action)
menu.addAction(self.delete_untracked_files_action)
menu.addSeparator()
menu.addAction(icons.edit(), N_('Add to .gitignore'),
menu.addAction(icons.edit(), N_('Ignore...'),
partial(gitignore.gitignore_view, self.context))

if not self.selection_model.is_empty():
Expand Down

0 comments on commit d66eda6

Please sign in to comment.