From 049c08d83921b8a3c6ae137d37e0b31f285e4f03 Mon Sep 17 00:00:00 2001 From: Arisu Tachibana Date: Tue, 21 Jan 2025 20:41:41 +0900 Subject: [PATCH] results: Use git rev-parse for getting commit hash This solve error when parsing detached head commit Signed-off-by: Arisu Tachibana --- docs/results.md | 24 ++++++++++++++++++++---- kcidev/subcommands/results.py | 13 ++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/docs/results.md b/docs/results.md index a637bc0..4906840 100644 --- a/docs/results.md +++ b/docs/results.md @@ -96,7 +96,7 @@ kci-dev results build --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git/ If used without arguments, `kci-dev results` subcommands will get KernelCI status of local checked out git repository for commands that require a giturl and branch. -In the following example, kci-dev is used on a local linux repository folder +In the following example, kci-dev is used on a local linux repository folder. This command work with every linux repository supported by KernelCI ```sh @@ -105,7 +105,6 @@ git folder: None tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git branch: master commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3 - pass/fail/inconclusive builds: 46/0/0 boots: 580/48/8 @@ -117,14 +116,31 @@ tests: 7858/6903/654 Get results automatically from a folder with a local linux repository. ```sh -kci-dev git:(master)$ kci-dev results --git-folder ../linux +kci-dev git:(master)$ kci-dev results summary --git-folder ../linux git folder: ../linux tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git branch: master commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3 - pass/fail/inconclusive builds: 46/0/0 boots: 580/48/8 tests: 7858/6903/654 ``` + +## --branch + +In the case of the script not been able to get the current branch information, +like in the case of a detached HEAD, it is possible to specify a branch. +Like in the following case: + +```sh +linux-cip git:(6077b17f20b1) kci-dev results summary --branch linux-5.10.y-cip +git folder: None +tree: https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git +branch: linux-5.10.y-cip +commit: 6077b17f20b1bcfeccaa23bc05573b938c47679d +pass/fail/inconclusive +builds: 21/0/0 +boots: 440/36/18 +tests: 1190/184/100 +``` diff --git a/kcidev/subcommands/results.py b/kcidev/subcommands/results.py index 3eb5240..4ebc46c 100644 --- a/kcidev/subcommands/results.py +++ b/kcidev/subcommands/results.py @@ -74,7 +74,7 @@ def is_inside_work_tree(git_folder): return False -def get_folder_repository(git_folder): +def get_folder_repository(git_folder, branch): kci_msg("git folder: " + str(git_folder)) if git_folder: current_folder = git_folder @@ -109,12 +109,15 @@ def get_folder_repository(git_folder): ) branch_name, branch_error = process.communicate() branch_name = branch_name.strip() + if branch: + branch_name = branch # Get last commit hash - last_commit_hash_path = os.path.join( - dot_git_folder, "refs", "heads", branch_name + process = subprocess.Popen( + ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, text=True ) - last_commit_hash = open(last_commit_hash_path, "r").read() + last_commit_hash, last_commit_hash_error = process.communicate() + last_commit_hash = last_commit_hash.strip() os.chdir(previous_folder) kci_msg("tree: " + git_url) @@ -240,7 +243,7 @@ def cmd_builds(data, commit, download_logs, status): def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder): if not giturl or not branch or not ((commit != None) ^ latest): - giturl, branch, commit = get_folder_repository(git_folder) + giturl, branch, commit = get_folder_repository(git_folder, branch) if latest: commit = get_latest_commit(origin, giturl, branch) return giturl, branch, commit