Skip to content

Commit 9d28846

Browse files
committed
Add lock-waiting to the standard run_command
1 parent f9b64b8 commit 9d28846

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

git.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,20 @@ class GitCommand(object):
216216
may_change_files = False
217217

218218
def run_command(self, command, callback=None, show_status=True,
219-
filter_empty_args=True, no_save=False, **kwargs):
219+
filter_empty_args=True, no_save=False, wait_for_lock=True, **kwargs):
220220
if filter_empty_args:
221221
command = [arg for arg in command if arg]
222222
if 'working_dir' not in kwargs:
223223
kwargs['working_dir'] = self.get_working_dir()
224224
if 'fallback_encoding' not in kwargs and self.active_view() and self.active_view().settings().get('fallback_encoding'):
225225
kwargs['fallback_encoding'] = self.active_view().settings().get('fallback_encoding').rpartition('(')[2].rpartition(')')[0]
226226

227+
root = git_root(self.get_working_dir())
228+
if wait_for_lock and root and os.path.exists(os.path.join(root, '.git', 'index.lock')):
229+
print("waiting for index.lock", command)
230+
do_when(lambda: not os.path.exists(os.path.join(root, '.git', 'index.lock')),
231+
self.run_command, command, callback=callback, show_status=show_status, filter_empty_args=filter_empty_args, no_save=no_save, wait_for_lock=wait_for_lock, **kwargs)
232+
227233
s = sublime.load_settings("Git.sublime-settings")
228234
if s.get('save_first') and self.active_view() and self.active_view().is_dirty() and not no_save:
229235
self.active_view().run_command('save')

0 commit comments

Comments
 (0)