-
Notifications
You must be signed in to change notification settings - Fork 398
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
git: spawn a separate git process for network operations #5228
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
That seems okay. It's also good to reorganize the current error enum as needed.
I think it's best to add a config knob to turn the shelling-out backend on. If the implementation gets stable enough, we can change the default, and eventually remove the git2 backend. I think the flag can be checked by CLI layer, but that's not a requirement. Regarding the code layout, maybe better to add new module for shelling-out implementation? The current git.rs isn't small, and there wouldn't be many codes to be shared. Thanks! |
Hi! Thanks for the feedback! In the meantime, I was trying to make CI pass and did away with the feature flag (which was always my intention anyways but wanted to receive feedback).
EDIT: I misread a comment where I thought it was saying no config knob. sorry about that |
Can you also squash it down to one commit and change the commit message/PR title to |
Getting rid of libgit2 is likely inevitable at this rate. It is only used for push/pull and is a large 3rd party dependency that we have probably outgrown by now, I'm almost certain the number one most-repeated bug report is "push does not work", with many users compiling themselves to fix. In reality I think it will probably remain a long tail of issues, things that won't work right, because the existing Git code, tools, and installers have a lot of quirks figured out for many various OS/workflow combinations, e.g. something like Git for Windows Credential Manager, or auto-ssh key unlock via secure enclaves, etc. In the future if it supported this stuff really well, bringing back the code probably wouldn't be too bad. Or maybe Gitoxide will get good support, which would be even better. But in the meantime, assuming this improves the user experience now, and assuming we turn it on by default at some point, it's probably no longer worth keeping git2 around. |
Thanks for taking up this task! I’ll try to do a more thorough review later but for now I wanted to mention that this should use the fancy Git (Also +1 to getting rid of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting work!
I looked into this, but am unsure this completely mimics the behaviour as it stands right now. The patch uses |
I agree. In fact, there is a current clippy warning about a function with too many arguments that is hard to go around without it. PS: I intend to work on the remaining issues on top of |
The version with the argument lets you specify the exact expected commit for each remote ref, so you should be able to implement the current logic on top of it. I think |
daa498e
to
5696825
Compare
Does this share functionality with #4759 ? At a surface level, it seems similar. |
I don't think it does. This PR is about using |
Re: The particular test case that fails regards if we are pushing a branch deletion, and the branch was already deleted on the remote (and as such, is not at the expected commit)
Would be great to get perspective on what to do here! cc @emilazy |
9a733d2
to
bb5e58c
Compare
19ae364
to
1c46afb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I would miss something, but this looks generally good to me. Thanks for working on this feature.
Fully qualified git refs (e.g., `+refs/head/main:refs/remotes/origin/main`) are commonly used throughout the git glue code. It is laborious and error prone to keep parsing refspecs when we need only a segment of it. This commits adds a type, `RefSpec`, which does exactly that
In some cases, there are non trivial codepaths for fetching multiple branches explicitly. In particular, it might be the case that fetching works for n = 2 but not n = 3. This commit changes a cli test to have 3 remotes and 3 branches, and a lib test with 3 branches, only one of them succeds.
Reasoning: `jj` fails to push/fetch over ssh depending on the system. Issue jj-vcs#4979 lists over 20 related issues on this and proposes spawning a `git` subprocess for tasks related to the network (in fact, just push/fetch are enough). This PR implements this. Implementation Details: This PR implements shelling out to `git` via `std::process::Command`. There are 2 sharp edges with the patch: - it relies on having to parse out git errors to match the error codes (and parsing git2's errors in one particular instance to match the error behaviour). This seems mostly unavoidable - to ensure matching behaviour with git2, the tests are maintained across the two implementations. This is done using test_case, as with the rest of the codebase Testing: Run the rust tests: ``` $ cargo test ``` Build: ``` $ cargo build ``` Clone a private repo: ``` $ path/to/jj git clone --config='git.subprocess=true' <REPO_SSH_URL> ``` Create new commit and push ``` $ echo "TEST" > this_is_a_test_file.txt $ path/to/jj describe -m 'test commit' $ path/to/jj git push --config='git.subprocess=true' -b <branch> ``` Issues Closed With a grain of salt, but most of these problems should be fixed (or at least checked if they are fixed). They are the ones listed in jj-vcs#4979 . SSH: - jj-vcs#63 - jj-vcs#440 - jj-vcs#1455 - jj-vcs#1507 - jj-vcs#2931 - jj-vcs#2958 - jj-vcs#3322 - jj-vcs#4101 - jj-vcs#4333 - jj-vcs#4386 - jj-vcs#4488 - jj-vcs#4591 - jj-vcs#4802 - jj-vcs#4870 - jj-vcs#4937 - jj-vcs#4978 - jj-vcs#5120 - jj-vcs#5166 Clone/fetch/push/pull: - jj-vcs#360 - jj-vcs#1278 - jj-vcs#1957 - jj-vcs#2295 - jj-vcs#3851 - jj-vcs#4177 - jj-vcs#4682 - jj-vcs#4719 - jj-vcs#4889 - jj-vcs#5147 - jj-vcs#5238 Notable Holdouts: - Interactive HTTP authentication (jj-vcs#401, jj-vcs#469) - libssh2-sys dependency on windows problem (can only be removed if/when we get rid of libgit2): jj-vcs#3984
Reasoning:
jj
fails to push/fetch over ssh depending on the system.Issue #4979 lists over 20 related issues on this and proposes spawning
a
git
subprocess for tasks related to the network (in fact, just push/fetchare enough).
This PR implements this.
Users can either enable shelling out to git in a config file:
Implementation Details:
This PR implements shelling out to
git
viastd::process::Command
.There are 2 sharp edges with the patch:
it relies on having to parse out git errors to match the error codes
(and parsing git2's errors in one particular instance to match the
error behaviour). This seems mostly unavoidable
to ensure matching behaviour with git2, the tests are maintained across the
two implementations. This is done using test_case, as with the rest
of the codebase
Testing:
Run the rust tests:
Build:
Clone a private repo:
Create new commit and push
Issues Closed
With a grain of salt, but most of these problems should be fixed (or at least checked if they are fixed). They are the ones listed in #4979 .
SSH:
ssh://
remote paths not supported. #2931jj git push
is not working for me on Windows #3322jj
can't set up new gitcredential.helper
entries #4101jj git fetch ...
/jj git clone ...
/ etc. with a FIDO2 (resident) key #4591jj git push
to GitHub repository: can't authenticate on macOS #4870Clone/fetch/push/pull:
jj git push
#1957jj git fetch --branch main
should fetch tags #2295SSL error: unknown error
#3851sso
origin fail withError: invalid argument: 'port'; class=Invalid (3)
#4177Notable Holdouts:
Checklist
If applicable:
CHANGELOG.md