helper: Allow pushing a raw SHA-1

This commit is contained in:
cloudhead 2024-04-18 17:09:45 +02:00
parent 4276a70eb1
commit 0b5fa51a92
No known key found for this signature in database
3 changed files with 26 additions and 2 deletions

View File

@ -3,6 +3,7 @@ Finally, we can also delete branches with `git push`:
``` ```
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/* $ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/*
145e1e69bef3ad93d14946ea212249c2fa9b9828 refs/heads/alice/1 145e1e69bef3ad93d14946ea212249c2fa9b9828 refs/heads/alice/1
ddcc1f164eacfd7dba41da9bff3261da3ee79fd3 refs/heads/alice/2
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
``` ```
@ -14,5 +15,6 @@ To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkE
``` ```
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/* $ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/*
ddcc1f164eacfd7dba41da9bff3261da3ee79fd3 refs/heads/alice/2
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
``` ```

View File

@ -76,3 +76,15 @@ If you pass an unsupported push option, you get an error:
$ git push -o alien rad HEAD:alice/2 $ git push -o alien rad HEAD:alice/2
error: unknown push option "alien" error: unknown push option "alien"
``` ```
We can also push a SHA-1:
```
$ git commit -m "Something good" --allow-empty -s
[alice/1 ddcc1f1] Something good
```
``` (stderr)
$ git push -o no-sync rad ddcc1f164eacfd7dba41da9bff3261da3ee79fd3:refs/heads/alice/2
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
* [new branch] ddcc1f164eacfd7dba41da9bff3261da3ee79fd3 -> alice/2
```

View File

@ -553,8 +553,18 @@ fn push<G: Signer>(
patches: patch::Cache<patch::Patches<'_, storage::git::Repository>, cob::cache::StoreWriter>, patches: patch::Cache<patch::Patches<'_, storage::git::Repository>, cob::cache::StoreWriter>,
signer: &G, signer: &G,
) -> Result<Option<ExplorerResource>, Error> { ) -> Result<Option<ExplorerResource>, Error> {
let head = working.find_reference(src.as_str())?; let head = match working.find_reference(src.as_str()) {
let head = head.peel_to_commit()?.id(); Ok(obj) => obj.peel_to_commit()?,
Err(e) => {
if let Ok(oid) = git::Oid::from_str(src.as_str()) {
working.find_commit(oid.into())?
} else {
return Err(e.into());
}
}
}
.id();
let dst = dst.with_namespace(nid.into()); let dst = dst.with_namespace(nid.into());
// It's ok for the destination reference to be unknown, eg. when pushing a new branch. // It's ok for the destination reference to be unknown, eg. when pushing a new branch.
let old = stored.backend.find_reference(dst.as_str()).ok(); let old = stored.backend.find_reference(dst.as_str()).ok();