diff --git a/tests/test_configs.py b/tests/test_configs.py index 8b8a45f..ff21751 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -497,6 +497,9 @@ class ConfigsTestCase(TestCase): } self.assertHeartbeatSent(heartbeat) + detected_proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read() + self.assertEquals(detected_proj, generated_proj) + self.assertHeartbeatNotSavedOffline() self.assertOfflineHeartbeatsSynced() self.assertSessionCacheSaved() diff --git a/tests/test_project.py b/tests/test_project.py index 8d4ece9..a2ed954 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -158,6 +158,13 @@ class ProjectTestCase(TestCase): entity='projects/wakatime_project_file/emptyfile.txt', ) + def test_wakatime_project_file_used_even_when_project_names_hidden(self): + self.shared( + expected_project='waka-project-file', + entity='projects/wakatime_project_file/emptyfile.txt', + extra_args=['--hide-project-names'], + ) + def test_git_project_detected(self): tempdir = tempfile.mkdtemp() shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git')) @@ -169,6 +176,33 @@ class ProjectTestCase(TestCase): entity=os.path.join(tempdir, 'git', 'emptyfile.txt'), ) + def test_get_project_not_used_when_project_names_hidden(self): + response = Response() + response.status_code = 0 + self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response + + tempdir = tempfile.mkdtemp() + shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git')) + shutil.move(os.path.join(tempdir, 'git', 'dot_git'), os.path.join(tempdir, 'git', '.git')) + + now = u(int(time.time())) + entity = os.path.join(tempdir, 'git', 'emptyfile.txt') + config = 'tests/samples/configs/good_config.cfg' + + args = ['--hide-project-names', '--file', entity, '--config', config, '--time', now] + + execute(args) + self.assertHeartbeatSavedOffline() + + self.assertNotEquals('git', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project']) + self.assertEquals(None, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch']) + proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read() + self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project']) + + execute(args) + + self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project']) + @log_capture() def test_ioerror_when_reading_git_branch(self, logs): logging.disable(logging.NOTSET) diff --git a/wakatime/arguments.py b/wakatime/arguments.py index 4fb2da0..71d80a3 100644 --- a/wakatime/arguments.py +++ b/wakatime/arguments.py @@ -335,7 +335,7 @@ def boolean_or_list(config_name, args, configs, alternative_names=[]): """Get a boolean or list of regexes from args and configs.""" # when argument flag present, set to wildcard regex - for key in alternative_names: + for key in alternative_names + [config_name]: if hasattr(args, key) and getattr(args, key): setattr(args, config_name, ['.*']) return diff --git a/wakatime/project.py b/wakatime/project.py index 70072f1..8aa7ca6 100644 --- a/wakatime/project.py +++ b/wakatime/project.py @@ -69,6 +69,8 @@ def get_project_info(configs, heartbeat, data): project_name = data.get('project') or heartbeat.args.project hide_project = heartbeat.should_obfuscate_project() + if hide_project and project_name is not None: + return project_name, None if project_name is None or branch_name is None: