Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.

Commit 8afc613

Browse files
committed
Fix bug causing random project names when hide project names enabled
1 parent 60b6968 commit 8afc613

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

tests/test_configs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ def test_obfuscte_project_names(self):
497497
}
498498
self.assertHeartbeatSent(heartbeat)
499499

500+
detected_proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
501+
self.assertEquals(detected_proj, generated_proj)
502+
500503
self.assertHeartbeatNotSavedOffline()
501504
self.assertOfflineHeartbeatsSynced()
502505
self.assertSessionCacheSaved()

tests/test_project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ def test_wakatime_project_file(self):
158158
entity='projects/wakatime_project_file/emptyfile.txt',
159159
)
160160

161+
def test_wakatime_project_file_used_even_when_project_names_hidden(self):
162+
self.shared(
163+
expected_project='waka-project-file',
164+
entity='projects/wakatime_project_file/emptyfile.txt',
165+
extra_args=['--hide-project-names'],
166+
)
167+
161168
def test_git_project_detected(self):
162169
tempdir = tempfile.mkdtemp()
163170
shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git'))
@@ -169,6 +176,33 @@ def test_git_project_detected(self):
169176
entity=os.path.join(tempdir, 'git', 'emptyfile.txt'),
170177
)
171178

179+
def test_get_project_not_used_when_project_names_hidden(self):
180+
response = Response()
181+
response.status_code = 0
182+
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
183+
184+
tempdir = tempfile.mkdtemp()
185+
shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git'))
186+
shutil.move(os.path.join(tempdir, 'git', 'dot_git'), os.path.join(tempdir, 'git', '.git'))
187+
188+
now = u(int(time.time()))
189+
entity = os.path.join(tempdir, 'git', 'emptyfile.txt')
190+
config = 'tests/samples/configs/good_config.cfg'
191+
192+
args = ['--hide-project-names', '--file', entity, '--config', config, '--time', now]
193+
194+
execute(args)
195+
self.assertHeartbeatSavedOffline()
196+
197+
self.assertNotEquals('git', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
198+
self.assertEquals(None, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch'])
199+
proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
200+
self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
201+
202+
execute(args)
203+
204+
self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
205+
172206
@log_capture()
173207
def test_ioerror_when_reading_git_branch(self, logs):
174208
logging.disable(logging.NOTSET)

wakatime/arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def boolean_or_list(config_name, args, configs, alternative_names=[]):
335335
"""Get a boolean or list of regexes from args and configs."""
336336

337337
# when argument flag present, set to wildcard regex
338-
for key in alternative_names:
338+
for key in alternative_names + [config_name]:
339339
if hasattr(args, key) and getattr(args, key):
340340
setattr(args, config_name, ['.*'])
341341
return

wakatime/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def get_project_info(configs, heartbeat, data):
6969
project_name = data.get('project') or heartbeat.args.project
7070

7171
hide_project = heartbeat.should_obfuscate_project()
72+
if hide_project and project_name is not None:
73+
return project_name, None
7274

7375
if project_name is None or branch_name is None:
7476

0 commit comments

Comments
 (0)