Skip to content

Commit 4bb004f

Browse files
LMGSantiago Cingolani
andauthored
Prepend refs/heads to base parameter as default (#664)
It falls back to user given input if prepended refname is not found Closes #616 Co-authored-by: Santiago Cingolani <[email protected]>
1 parent 79480c1 commit 4bb004f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

josh-proxy/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ pub fn process_repo_update(repo_update: RepoUpdate) -> josh::JoshResult<String>
8080
};
8181

8282
let original_target_ref = if let Some(base) = push_options.get("base") {
83-
transaction.refname(base)
83+
// Allow user to use just the branchname as the base:
84+
let full_path_base_refname = transaction.refname(&format!("refs/heads/{}", base));
85+
if transaction
86+
.repo()
87+
.refname_to_id(&full_path_base_refname)
88+
.is_ok()
89+
{
90+
full_path_base_refname
91+
} else {
92+
transaction.refname(base)
93+
}
8494
} else {
8595
transaction.refname(&baseref)
8696
};
@@ -97,7 +107,7 @@ pub fn process_repo_update(repo_update: RepoUpdate) -> josh::JoshResult<String>
97107
return Err(josh::josh_error(&unindent::unindent(&format!(
98108
r###"
99109
Reference {:?} does not exist on remote.
100-
If you want to create it, pass "-o base=refs/heads/<branchname>"
110+
If you want to create it, pass "-o base=<basebranch>" or "-o base=path/to/ref"
101111
to specify a base branch/reference.
102112
"###,
103113
baseref

tests/proxy/push_new_branch.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Check the branch pushed
6363
* [new branch] new-branch -> origin/new-branch
6464
$ [ "${SHA1}" = "$(git log --max-count=1 --format='%H' origin/new-branch)" ] || echo "SHA1 differs after push!"
6565

66-
Add one more commit in the workspace
66+
Add one more commit in the workspace and push using implicit prefix in base
6767

6868
$ cd ${TESTTMP}/sub
6969
$ echo test > test.txt
@@ -72,7 +72,7 @@ Add one more commit in the workspace
7272
[new-branch 751ef45] test commit
7373
1 file changed, 1 insertion(+)
7474
create mode 100644 test.txt
75-
$ git push origin new-branch -o base=refs/heads/master
75+
$ git push origin new-branch -o base=master
7676
remote: josh-proxy
7777
remote: response from upstream:
7878
remote: To http://localhost:8001/real_repo.git

tests/proxy/push_subtree.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
remote: josh-proxy
2626
remote: response from upstream:
2727
remote: Reference "refs/heads/new_branch" does not exist on remote.
28-
remote: If you want to create it, pass "-o base=refs/heads/<branchname>"
28+
remote: If you want to create it, pass "-o base=<basebranch>" or "-o base=path/to/ref"
2929
remote: to specify a base branch/reference.
3030
remote:
3131
remote:

0 commit comments

Comments
 (0)