Skip to content

Commit 4aa1d91

Browse files
Migrate user's existing exclude patterns on first launch
1 parent eb6b9e4 commit 4aa1d91

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

gitignore_plugin.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def start(): # Gets invoked at the bottom of this file.
1414
Regularly (every 5s) updates the file_exclude_patterns setting from a
1515
background thread.
1616
"""
17+
if is_first_launch():
18+
migrate_exclude_patterns()
19+
record_first_launch()
20+
1721
def run():
1822
while True:
1923
update_file_exclude_patterns()
@@ -171,4 +175,25 @@ def repo_ignored_paths(git_repo):
171175

172176
return absolute_paths
173177

178+
def is_first_launch():
179+
s = sublime.load_settings("gitignorer.sublime-settings")
180+
return not s.get('_sublime_gitignorer_has_run', False)
181+
182+
def migrate_exclude_patterns():
183+
"""
184+
Runs on first launch; purpose is to prevent people who have already set
185+
exclusion patterns from losing them when they install this package.
186+
"""
187+
s = sublime.load_settings("Preferences.sublime-settings")
188+
existing_file_exclude_patterns = s.get('file_exclude_patterns', [])
189+
existing_folder_exclude_patterns = s.get('folder_exclude_patterns', [])
190+
s.set('extra_file_exclude_patterns', existing_file_exclude_patterns)
191+
s.set('extra_folder_exclude_patterns', existing_folder_exclude_patterns)
192+
sublime.save_settings("Preferences.sublime-settings")
193+
194+
def record_first_launch():
195+
s = sublime.load_settings("gitignorer.sublime-settings")
196+
s.set('_sublime_gitignorer_has_run', True)
197+
sublime.save_settings("gitignorer.sublime-settings")
198+
174199
start()

0 commit comments

Comments
 (0)