-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a remote URL to a local_only repository fails to set the upstream branch for master #424
Comments
The code for Fixing the initial branch name of local reposThe local-only repo is created by cargo-crev/crev-lib/src/local.rs Line 525 in f542891
and renamed to a URL-based name by cargo-crev/crev-lib/src/local.rs Line 684 in f542891
If you run If you run Do you configure I think hard-coding local-only repos to have a Fixing adding a remote URLCurrently crev adds the origin URL at cargo-crev/crev-lib/src/local.rs Line 568 in f542891
Currently crev sets a refspec if it clones a URL-based repo, but not if it renames a pre-existing local-only repo into a URL-based repo. I think that creating a differently-configured repo based on prior state is a bug. In the current code organization (which I didn't change), The diff --git a/crev-lib/src/local.rs b/crev-lib/src/local.rs
index 0cdd201..b3072ac 100644
--- a/crev-lib/src/local.rs
+++ b/crev-lib/src/local.rs
@@ -565,7 +565,13 @@ impl Local {
info!("Using existing repository `{}`", proof_dir.display());
match git2::Repository::open(&proof_dir) {
Ok(repo) => {
- repo.remote_set_url("origin", &push_url)?;
+ match repo.remote("origin", &push_url) {
+ Ok(_) => (),
+ Err(e) if e.code() == git2::ErrorCode::Exists => {
+ repo.remote_set_url("origin", &push_url)?;
+ },
+ Err(e) => return Err(e.into()),
+ }
}
Err(_) => {
git2::Repository::init_opts( Fixing the upstream branch and
|
let _ = self.run_git(vec!["pull".into(), "--rebase".into(), "-Xours".into()]); |
--set-upstream origin master
(which should work, as long as the template continues to call its default branch master). Alternatively you can get the branch name from origin/HEAD
. As mentioned in "Fixing the initial branch name of local repos", we may need to rename the local branch to match the template repo's default branch.
How should I obtain the remote's default branch name? Do I hard-code it as master (which works if everyone uses the template repo and the default branch name doesn't change)? Shell out to git rev-parse --abbrev-ref origin/HEAD
(which fails if the remote repo isn't a template repo, but rather empty and has no branches)? Or try to figure out how to do it in libgit2 (and if the remote repo has no default branch, keep the local branch name)?
Is supporting non-master
remote branches necessary?
I don't understand the web side of crev. Do you require that all repos are forks of the github/gitlab template, and use the fork list to for humans or programs to discover proof repos (meaning that self-hosted non-GitHub/GitLab repos can't be discovered)? Is the list of forks not used for the program to discover repos (but rather other people's repos)?
Are people allowed to create remote repos not based off https://github.com/crev-dev/crev-proofs and b82d8bb22935437787c715c6452b21865b27a3bd? Do remote repos whose default branch isn't master
get properly fetched? (I didn't test.)
I admit I didn't read your entire posts, but I can answer the questions at the end. Please keep in mind that I'm not an author of the program, just a user of a few years — I might be wrong on some points. The crev-dev/crev-proofs template exists for autodiscovery; https://gitlab.com/crev-dev/auto-crev-proofs collects its forks, so users can "subscribe" to that one repo and learn about other ones automatically. It's not a requirement to create your proofs repo from a template, but if you create your own, you won't get auto-discovered by auto-crev-proofs. Self-hosting is also allowed, but also won't get auto-discovered by auto-crev-proofs. As I understand it, cargo-crev fetches all the repos of all known identities, so a non-template/self-hosted repo will get known to others once someone in the existing network adds a trust record for this repo (at whatever level). I don't know if crev requires the main branch to be called |
Hi. Thanks for taking a look into it. The current code is the result of me implementing some basic stuff with What you were trying to do is nowhere near what I would have anticipated. The supported use case is really: create a repo remotely first, I'm happy to have more use-cases supported, so I will gladly accept a PR. As for the |
I tried setting up
cargo crev
as a reviewer, using 0.21.3 installed fromcargo install
, on Arch Linux. I was unable tocargo crev publish
.To reproduce this issue, I first removed/renamed
~/.config/crev
, then ran the following commands:cargo crev trust --level high https://github.com/dpc/crev-proofs
created~/.config/crev/proofs/local_only_…
.Then I tried setting up as a reviewer, using
cargo crev id set-url https://github.com/nyanpasu64/crev-proofs
(I thinkcargo crev id new --url https://github.com/nyanpasu64/crev-proofs
does the same thing).Then I tried running
cargo crev publish
, but apparently/home/nyanpasu64/.config/crev/proofs/github_com_nyanpasu64_crev-proofs-…
was missing an upstream branch:Investigation
I restarted the process, but ran
strace -fs999 -o crev-set-url cargo crev id set-url https://github.com/nyanpasu64/crev-proofs
instead. The log file shows that crev moves thelocal_only
repository to~/.config/crev/proofs/github_com_nyanpasu64_crev-proofs-…
, adds a remote by editing.git/config
directly (not via agit remote
child process), then runsgit pull --rebase
on the remote-tracking branch, but fails to set the upstream.I think you added the remote unusually. If I look into
.git/config
, I see the following (missing afetch
tag):When I run
git fetch [origin [master]]
, I get the following output, and noorigin/master
ref created, andcargo crev publish
fails:Is this deliberate?
Fixing the repo
If I recreate the remote using
git remote remove origin && git remote add origin git@github.com:nyanpasu64/crev-proofs.git
, it adds the following:And fetching creates an
origin/master
ref:But then
git pull --rebase -Xours
doesn't work properly:If you instead run
git pull --rebase -Xours --set-upstream origin master
(I don't know what-Xours
does but it's probably not important), it works and I cancargo crev publish
:Fixing crev
I'm still looking into it.
The text was updated successfully, but these errors were encountered: