Skip to content

Commit

Permalink
Fix sha based request in combination with hbs (#1320)
Browse files Browse the repository at this point in the history
The case where a sha was passed instead of a ref was not
handled in the code for rendering hbs files.

Change: fix-sha-hbs
  • Loading branch information
christian-schilling authored Mar 20, 2024
1 parent fa8a7e0 commit 8810504
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions josh-proxy/src/bin/josh-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,9 +1402,13 @@ async fn serve_query(
.unwrap(),
)?;

let commit_id = transaction_mirror
.repo()
.refname_to_id(&transaction_mirror.refname(&head_ref))?;
let commit_id = if let Ok(oid) = git2::Oid::from_str(&head_ref) {
oid
} else {
transaction_mirror
.repo()
.refname_to_id(&transaction_mirror.refname(&head_ref))?
};
let commit_id =
josh::filter_commit(&transaction, filter, commit_id, josh::filter::empty())?;

Expand Down
11 changes: 11 additions & 0 deletions tests/proxy/query.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Now render still works (used to fail if filtered previously)
param: 12345
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e

$ curl -s -i http://localhost:8002/real_repo.git?render=tmpl_file\&param_val=12345 | grep -v date:
HTTP/1.1 200 OK\r (esc)
content-type: text/plain\r (esc)
Expand All @@ -78,6 +79,16 @@ Now render still works (used to fail if filtered previously)
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e

$ curl -s http://localhost:8002/real_repo.git@refs/heads/master?render=tmpl_file\&param_val=12345 | grep -v date:
param: 12345
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e

$ curl -s http://localhost:8002/real_repo.git@890148bbaa6a797bac8aef672a437f2b08635f15?render=tmpl_file\&param_val=12345 | grep -v date:
param: 12345
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e

Graphql works
$ curl -s http://localhost:8002/real_repo.git?graphql=x.graphql
{
Expand Down

0 comments on commit 8810504

Please sign in to comment.