diff --git a/graal/graal.py b/graal/graal.py index 1aa763a..139bdc3 100644 --- a/graal/graal.py +++ b/graal/graal.py @@ -459,8 +459,14 @@ class GraalCommand(GitCommand): def _pre_init(self): """Initialize repositories directory path""" - git_path = self.parsed_args.git_path - setattr(self.parsed_args, 'gitpath', git_path) + if not self.parsed_args.git_path: + base_path = os.path.expanduser('~/.graal/repositories/') + processed_uri = self.parsed_args.uri.lstrip('/') + git_path = os.path.join(base_path, processed_uri) + '-git' + else: + git_path = self.parsed_args.git_path + + setattr(self.parsed_args, 'git_path', git_path) @staticmethod def setup_cmd_parser(categories, exec_path=False): diff --git a/tests/test_graal.py b/tests/test_graal.py index c132d69..dd82e49 100644 --- a/tests/test_graal.py +++ b/tests/test_graal.py @@ -616,9 +616,17 @@ def test_backend_class(self): self.assertIs(GraalCommand.BACKEND, Graal) - def test_gitpath_init(self): + @unittest.mock.patch('os.path.expanduser') + def test_gitpath_init(self, mock_expanduser): """Test gitpath initialization""" + mock_expanduser.return_value = os.path.join(self.tmp_path, 'testpath') + args = ['http://example.com/'] + + cmd = MockedGraalCommand(*args) + self.assertEqual(cmd.parsed_args.git_path, + os.path.join(self.tmp_path, 'testpath/http://example.com/' + '-git')) + args = ['http://example.com/', '--git-path', '/tmp/gitpath']