-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Fix 100725: Allow empty repositories to be synced #114163
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
base: main
Are you sure you want to change the base?
Conversation
I'm definitely hesitant to change the default behavior, but I think its probably a decent fallback. I've started a discussion for this here: git-for-windows/git#2981 to see what any Git maintainers might think. |
@eamodio, with the answer from @derrickstolee in git-for-windows/git#2981 should I revert the last commit and add |
Yeah I think we should add it as a fallback. |
I have reverted the commit and Somehow, the windows tests are now failing. I believe that this is not related to my changes (other PRs are also failing). Maybe you could take a quick look at it. Are there any other changes I should include? Or is this PR good to go (once the pipeline succeeds)? |
I am looking forward to merging this PR. @eamodio, have you already had the time to look at my questions? |
@eamodio I hope you are doing well. |
@eamodio |
@joaomoreno, I haven't heard from @eamodio in a while (probably he is busy). |
@joaomoreno, @eamodio I hope you are doing well. Thank you very much |
@plainerman I understand how frustrating it might be to just see your work pending here. But I have to ask for patience. We have no estimate right now. We're just busy with many other tasks right now. @eamodio will look into this when he carves out the time. Thanks! |
@plainerman sorry for the delay. Can you please update this with the current Also can you combine the extra git calls into a single call? Here is what I have in GitLens: https://github.com/eamodio/vscode-gitlens/blob/b60637f00e245fd23c84ceebf7a4aeb637c64d96/src/git/git.ts#L1255-L1274 |
Thank you for your responses! I will incorporate the desired changes and will ping you @eamodio once I have changed this. |
Executing git rev-parse on an empty repository does not work and sets no upstream (although there exists one)
Syncing a repository does not need a commit, whereas publishing a new branch does
Sorry @eamodio, I was busy the last days. The branch is now ready again. I rebased the branch and combined the git config fetch into a single call. If there is anything I can do, just ping me. To test it locally, you can use this empty repository. that has a commit but is not synced. |
@lszomoru, I am glad to help if you need any assistance or have further questions. |
@plainerman, first of all I would like to apologise that it is taking so long for this change to be committed. I have taken a look at your code today, and I have manually ported the two changes to the latest codebase in main. Unfortunately I am still seeing errors when I do the following:
When I open the repository, with your changes the I will further investigate the issue this week but please feel free to look at it yourself If you have time. |
Thanks @lszomoru for the update. Maybe, I'll have time this weekend. Have you pushed the changes you made to my repository? I believe you have push permissions there, as you are a member here. Or should I rebase myself? |
@plainerman, no I have not pushed any changes to your topic branch. |
Is this still relevant? |
This PR fixes #100725 and allows VSCode to properly sync git repositories that have been cloned before there were any commits.
Reproducing and Testing
To test it, I have attached a zip file with an empty git repository that now has commits (i.e. should be syncable).
If you feel uncomfortable downloading files from strangers, see below for git commands to simulate this state.
git pull
works just fine.With the proposed fix, clicking the sync button works and syncs the repository as intended.
Proposed Changes
As described in the issue (#100725), the root cause is that the command used to fetch the upstream (
git rev-parse
) fails on an empty repository. This then causes this unexpected behavior.I propose the following changes to resolve the issue:
extensions/git/src/git.ts
method:getBranch(...)
Although the commit cannot be fetched for an empty repository, without this catch the function is exited. The commit should be left undefined, while still properly fetching the upstream.
Once a branch has an upstream, it will be stored in the git config. Unfortunately, this command uses an older syntax of git, so we have to manually construct the full upstream path. See this stackoverflow post for more information about this section of the git config.
extensions/git/src/statusbar.ts
method:command()
3. Do not require commit for syncing
Syncing a repository does not require a commit, whereas publishing does (git does not allow pushing branches without a history).
In combination with the proposed changes above, this makes the sync button clickable.
You might feel uncomfortable changing from
git-rev
togit-config
in all cases. Although I strongly believe that this should not be a problem and did not cause any issues whatsoever in my tests: If you feel so, I am open for discussion. In the worst case, I can revert the last commit and we usegit-config
as a fallback. This can be seen in this commit: 4f3d47cPersonally, I would prefer the current changes.
Simulate a freshly cloned empty git repo