def sparse_branch_checkout_remote_repo_skip_clone(
- remote_repo, remote_branch_name, local_branch_name
+ remote_repo: str, remote_branch_name: str, local_branch_name: str, commit_sha: str
) -> Repo:
repo = Repo(".", search_parent_directories=True)
git_cmd = repo.git
"--depth=1",
)
+ if commit_sha:
+ git_cmd.fetch(
+ REMOTE_REPO_GIT_REMOTE_NAME,
+ commit_sha,
+ "--depth=1",
+ )
+
if not folder_exists_in_branch(local_branch_name, git_cmd, CEPH_CONFIG_OPTIONS_FOLDER_PATH):
git_cmd.sparse_checkout("add", CEPH_CONFIG_OPTIONS_FOLDER_PATH)
git_cmd.checkout()
return repo
-def sparse_branch_checkout_skip_clone(branch_name) -> Repo:
+def sparse_branch_checkout_skip_clone(branch_name: str, commit_sha: str) -> Repo:
repo = Repo(".", search_parent_directories=True)
git_cmd = repo.git
"--depth=1",
)
+ if commit_sha:
+ git_cmd.fetch(
+ "origin",
+ commit_sha,
+ "--depth=1",
+ )
+
if not folder_exists_in_branch(branch_name, git_cmd, CEPH_CONFIG_OPTIONS_FOLDER_PATH):
git_cmd.sparse_checkout("add", CEPH_CONFIG_OPTIONS_FOLDER_PATH)
git_cmd.checkout()
return repo
-def sparse_branch_checkout(repo_url: str, branch_name: str) -> tempfile.TemporaryDirectory[str]:
+def sparse_branch_checkout(
+ repo_url: str, branch_name: str, commit_sha: str = None
+) -> tempfile.TemporaryDirectory[str]:
"""
Clone a sparse branch and checkout the required folder.
"--depth=1",
],
)
+
git_cmd = repo.git
+ if commit_sha:
+ git_cmd.fetch(
+ "origin",
+ commit_sha,
+ "--depth=1",
+ )
git_cmd.sparse_checkout("add", CEPH_CONFIG_OPTIONS_FOLDER_PATH)
- git_cmd.checkout()
+ if commit_sha:
+ git_cmd.checkout("FETCH_HEAD")
+ else:
+ git_cmd.checkout()
repo.close()
return config_tmp_dir
ref_branch: str,
remote_repo: str,
cmp_branch: str,
+ ref_commit_sha: str,
+ cmp_commit_sha: str,
skip_clone: bool,
format_type: str,
):
format_type (str): How should the results be printed.
"""
final_result = {}
+ ref_config_dict = {}
+ config_dict = {}
if skip_clone:
cmp_branch_local_branch_name = REMOTE_REPO_GIT_REMOTE_NAME + "/" + cmp_branch
- ref_git_repo = sparse_branch_checkout_skip_clone(ref_branch)
+ ref_git_repo = sparse_branch_checkout_skip_clone(ref_branch, ref_commit_sha)
remote_git_repo = sparse_branch_checkout_remote_repo_skip_clone(
- remote_repo, cmp_branch, cmp_branch_local_branch_name
+ remote_repo, cmp_branch, cmp_branch_local_branch_name, cmp_commit_sha
)
- ref_config_dict = git_show_yaml_files(ref_branch, ref_git_repo)
+ if ref_commit_sha:
+ ref_config_dict = git_show_yaml_files(ref_commit_sha, ref_git_repo)
+ else:
+ ref_config_dict = git_show_yaml_files(ref_branch, ref_git_repo)
# To show the files from remote repo, you need to append the remote name
# before the branch
- config_dict = git_show_yaml_files(cmp_branch_local_branch_name, remote_git_repo)
+ if cmp_commit_sha:
+ config_dict = git_show_yaml_files(cmp_commit_sha, remote_git_repo)
+ else:
+ config_dict = git_show_yaml_files(cmp_branch_local_branch_name, remote_git_repo)
final_result = diff_config(ref_config_dict, config_dict)
ref_git_repo.close()
remote_git_repo.close()
else:
- ref_repo_tmp_dir = sparse_branch_checkout(ref_repo, ref_branch)
- cmp_repo_tmp_dir = sparse_branch_checkout(remote_repo, cmp_branch)
+ if ref_commit_sha:
+ ref_repo_tmp_dir = sparse_branch_checkout(
+ ref_repo, ref_branch, commit_sha=ref_commit_sha
+ )
+ else:
+ ref_repo_tmp_dir = sparse_branch_checkout(ref_repo, ref_branch)
+ if cmp_commit_sha:
+ cmp_repo_tmp_dir = sparse_branch_checkout(
+ remote_repo, cmp_branch, commit_sha=cmp_commit_sha
+ )
+ else:
+ cmp_repo_tmp_dir = sparse_branch_checkout(remote_repo, cmp_branch)
ref_config_dict = load_config_yaml_files(Path(ref_repo_tmp_dir.name))
config_dict = load_config_yaml_files(Path(cmp_repo_tmp_dir.name))
final_result = diff_config(ref_config_dict, config_dict)
parser_diff_branch_remote_repo.add_argument(
"--cmp-branch", required=True, help="the branch to compare against"
)
+ parser_diff_branch_remote_repo.add_argument(
+ "--ref-commit-sha", required=False, help="the reference commit"
+ )
+ parser_diff_branch_remote_repo.add_argument(
+ "--cmp-commit-sha", required=False, help="the commit to compare against"
+ )
parser_diff_branch_remote_repo.add_argument(
"--skip-clone",
action="store_true",
if args.skip_clone and args.ref_repo != CEPH_UPSTREAM_REMOTE_URL:
parser.error("--ref-repo cannot be set if --skip-clone is used.")
+ if args.ref_commit_sha and not args.ref_branch:
+ parser.error("--ref-commit-sha needs --ref-branch to be set.")
+
+ if args.cmp_commit_sha and not args.cmp_branch:
+ parser.error("--cmp-commit-sha needs --cmp-branch to be set.")
+
if args.mode == "diff-branch":
diff_branch(args.ref_repo, args.ref_branch, args.cmp_branch, args.skip_clone, args.format)
args.ref_branch,
args.remote_repo,
args.cmp_branch,
+ args.ref_commit_sha,
+ args.cmp_commit_sha,
args.skip_clone,
args.format,
)