diff --git a/main.py b/main.py index 3826adc..9c8ef15 100644 --- a/main.py +++ b/main.py @@ -101,6 +101,36 @@ def is_git_directory(dir): git_dir_path = os.path.join(dir, '.git') return os.path.exists(git_dir_path) and os.path.isdir(git_dir_path) +def get_target_data(url, branch, commit, directory): + ''' + Get target repository data + + Parameters: + url (str): repository url + branch(str): branch name + commit(str): commit # + directory (str): directory to clone in + ''' + project_name = get_repository_name(url) + if (os.path.exists(os.path.join(directory, project_name))): + print(f"{project_name} repository already exists. Aborting cloning") + return + + clone_command = ["git", "clone"] + if branch: + clone_command.extend(["-b", branch]) + if not commit: + clone_command.extend(["--depth", "1"]) + clone_command.append(url) + subprocess.run(clone_command, cwd=directory) # targetted clone is fast, no need to reuse existing one. + else: + clone_command.append(url) + subprocess.run(clone_command, cwd=directory) + checkout_commit(commit, os.path.join(directory, get_repository_name(url))) + + cmd_str = ' '.join(clone_command) + print(f"get_target_data -> {cmd_str}") + def clone_repository(url, directory): ''' Clone a repository from 'url' in 'directory' @@ -172,7 +202,7 @@ def clone_specimin(path_to_clone, url): if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path): perform_git_pull(spcimin_source_path) else: - clone_repository(url, path_to_clone) + get_target_data(url, "", "", path_to_clone) def build_specimin_command(project_name: str, @@ -300,15 +330,10 @@ def performEvaluation(issue_data) -> Result: issue_folder_abs_dir = os.path.abspath(issue_folder_dir) input_dir = create_issue_directory(issue_folder_abs_dir, issue_id) - clone_repository(url, input_dir) - repo_name = get_repository_name(url) - if branch: - change_branch(branch, os.path.join(input_dir, repo_name)) + get_target_data(url, branch, commit_hash, input_dir) - if commit_hash: - checkout_commit(commit_hash, os.path.join(input_dir, repo_name)) - + repo_name = get_repository_name(url) specimin_command = "" result: Result = None specimin_path = get_specimin_env_var() diff --git a/resources/test_data.json b/resources/test_data.json index 364de9e..fbea10c 100644 --- a/resources/test_data.json +++ b/resources/test_data.json @@ -1,9 +1,9 @@ [ { "issue_id" : "cf-1291", - "url": "https://github.com/codespecs/daikon.git", - "branch": "", - "commit_hash": "15d7c2d84", + "url": "https://github.com/tahiat/daikon.git", + "branch": "cf-1291", + "commit_hash": "", "project_name": "daikon", "build_command": "this can be cf command or java", "root_dir": "java", @@ -39,9 +39,9 @@ }, { "issue_id" : "cf-6077", - "url": "https://github.com/jacek-lewandowski/cassandra.git", - "branch": "checker-framework-testing", - "commit_hash": "7b3c4ce8e5d6da41791492903ec367b8857cd57d", + "url": "https://github.com/tahiat/cassandra.git", + "branch": "cf-6077", + "commit_hash": "", "project_name": "cassandra", "build_command": "ant cf-only -Dcf.check.only=org/apache/cassandra/index/sasi/conf/IndexMode.java", "root_dir": "src/java", @@ -328,8 +328,8 @@ }, { "issue_id" : "cf-6388", - "url": "https://github.com/kennknowles/beam.git", - "branch": "checkerframework-StructuralEqualityComparer", + "url": "https://github.com/tahiat/beam.git", + "branch": "cf-6388", "commit_hash": "", "project_name": "beam", "build_command": "checkerframework-StructuralEqualityComparer",