Skip to content

Commit 049c08d

Browse files
committed
results: Use git rev-parse for getting commit hash
This solve error when parsing detached head commit Signed-off-by: Arisu Tachibana <arisu.tachibana@miraclelinux.com>
1 parent 3fb51c6 commit 049c08d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

docs/results.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ kci-dev results build --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git/
9696

9797
If used without arguments, `kci-dev results` subcommands will get KernelCI status
9898
of local checked out git repository for commands that require a giturl and branch.
99-
In the following example, kci-dev is used on a local linux repository folder
99+
In the following example, kci-dev is used on a local linux repository folder.
100100
This command work with every linux repository supported by KernelCI
101101

102102
```sh
@@ -105,7 +105,6 @@ git folder: None
105105
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
106106
branch: master
107107
commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3
108-
109108
pass/fail/inconclusive
110109
builds: 46/0/0
111110
boots: 580/48/8
@@ -117,14 +116,31 @@ tests: 7858/6903/654
117116
Get results automatically from a folder with a local linux repository.
118117

119118
```sh
120-
kci-dev git:(master)$ kci-dev results --git-folder ../linux
119+
kci-dev git:(master)$ kci-dev results summary --git-folder ../linux
121120
git folder: ../linux
122121
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
123122
branch: master
124123
commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3
125-
126124
pass/fail/inconclusive
127125
builds: 46/0/0
128126
boots: 580/48/8
129127
tests: 7858/6903/654
130128
```
129+
130+
## --branch
131+
132+
In the case of the script not been able to get the current branch information,
133+
like in the case of a detached HEAD, it is possible to specify a branch.
134+
Like in the following case:
135+
136+
```sh
137+
linux-cip git:(6077b17f20b1) kci-dev results summary --branch linux-5.10.y-cip
138+
git folder: None
139+
tree: https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git
140+
branch: linux-5.10.y-cip
141+
commit: 6077b17f20b1bcfeccaa23bc05573b938c47679d
142+
pass/fail/inconclusive
143+
builds: 21/0/0
144+
boots: 440/36/18
145+
tests: 1190/184/100
146+
```

kcidev/subcommands/results.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def is_inside_work_tree(git_folder):
7474
return False
7575

7676

77-
def get_folder_repository(git_folder):
77+
def get_folder_repository(git_folder, branch):
7878
kci_msg("git folder: " + str(git_folder))
7979
if git_folder:
8080
current_folder = git_folder
@@ -109,12 +109,15 @@ def get_folder_repository(git_folder):
109109
)
110110
branch_name, branch_error = process.communicate()
111111
branch_name = branch_name.strip()
112+
if branch:
113+
branch_name = branch
112114

113115
# Get last commit hash
114-
last_commit_hash_path = os.path.join(
115-
dot_git_folder, "refs", "heads", branch_name
116+
process = subprocess.Popen(
117+
["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, text=True
116118
)
117-
last_commit_hash = open(last_commit_hash_path, "r").read()
119+
last_commit_hash, last_commit_hash_error = process.communicate()
120+
last_commit_hash = last_commit_hash.strip()
118121

119122
os.chdir(previous_folder)
120123
kci_msg("tree: " + git_url)
@@ -240,7 +243,7 @@ def cmd_builds(data, commit, download_logs, status):
240243

241244
def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder):
242245
if not giturl or not branch or not ((commit != None) ^ latest):
243-
giturl, branch, commit = get_folder_repository(git_folder)
246+
giturl, branch, commit = get_folder_repository(git_folder, branch)
244247
if latest:
245248
commit = get_latest_commit(origin, giturl, branch)
246249
return giturl, branch, commit

0 commit comments

Comments
 (0)