Skip to content
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

Tracking breaks after rebasing a clone/pull commit parent #600

Open
ehsan-adi opened this issue Oct 17, 2023 · 8 comments
Open

Tracking breaks after rebasing a clone/pull commit parent #600

ehsan-adi opened this issue Oct 17, 2023 · 8 comments

Comments

@ehsan-adi
Copy link

A subrepo pull or subrepo clone commit saves the SHA of the parent commit into the .gitrepo:subrepo.parent config. If this parent is later on changed due to a rebase, subrepo.parent becomes invalid, which breaks tracking. I suspect the main command that breaks is subrepo branch.
Could this be fixed by getting the parent through rev-parse or some other method that works well with rebases? Or is this a limitation of the tool?

@admorgan
Copy link
Collaborator

This is a limitation of the tool. parent is used for most git subrepo operations. The root of the problem is that we are stitching two repositories together keeping just enough information to be able to derive what is local and what is remote. The fact that rebase can break this tenuous link is the longest standing enhancement request. Unfortunately, I have not come up with a design that doesn't require git subrepo to be a part of the official git project to work around it. I personally have a git hook that checks to ensure that I didn't break the parent link. I could include that in the repo and add tooling to install that that in your git hooks as a band-aid.

@MaurGi
Copy link

MaurGi commented Oct 24, 2023

This is very frequent operation - could be a deal breaker for us in using git subrepo.

Normal flow:

  • From master, we create a feature branch
  • We make changes to the feature branch
  • Now we git subrepo pull <path> - the parent is now set to the previous commit in the feature branch.
  • Now we squash merge the feature branch into master via a PR.

Problem: the previous commit is gone due to the squash, git subrepo can't pull anymore.

Any suggestion how to workaround this?

@MaurGi
Copy link

MaurGi commented Oct 24, 2023

This is a limitation of the tool. parent is used for most git subrepo operations. The root of the problem is that we are stitching two repositories together keeping just enough information to be able to derive what is local and what is remote. The fact that rebase can break this tenuous link is the longest standing enhancement request. Unfortunately, I have not come up with a design that doesn't require git subrepo to be a part of the official git project to work around it. I personally have a git hook that checks to ensure that I didn't break the parent link. I could include that in the repo and add tooling to install that that in your git hooks as a band-aid.

could you share this hook?

@MaurGi
Copy link

MaurGi commented Nov 17, 2023

@admorgan Have you thought about going back to the last commit in the default branch (master/main or whatever) and using that as the base when doing pull rather than using the current commit sha?
The base commit ID is of the current repo, the problem is that we lose the history when we rebase, but most of the rebases are with master and that remains in the history?

@Muzak93
Copy link

Muzak93 commented Jan 12, 2024

Normal flow:

  • From master, we create a feature branch
  • We make changes to the feature branch
  • Now we git subrepo pull <path> - the parent is now set to the previous commit in the feature branch.
  • Now we squash merge the feature branch into master via a PR.

Problem: the previous commit is gone due to the squash, git subrepo can't pull anymore.

Any suggestion how to workaround this?

Yeah this is a very similar situation here! This especially problematic since I cannot merge into main directly! Is there any idea how this could be fixed?

Could there be a "main_commit" which git subrepo uses instead if we are in a different branch?

Maybe something like this? So one can explicitly set the parent?
git subrepo pull subdir --use-parent=THE SHA of the parent

@MaurGi
Copy link

MaurGi commented Jan 25, 2024

FYI - I ended up going with this - when I need to pull a change, I create a branch from master specifically for the subrepo update, then I pull the changes and I PR exclusively that change, then merge and rebase my feature branch on that.

@Muzak93
Copy link

Muzak93 commented Jan 25, 2024

Do you have a link to the pr / branch?

@taktran
Copy link

taktran commented Apr 17, 2024

I found a potential fix for this issue here: #617

admorgan added a commit to admorgan/git-subrepo that referenced this issue Jul 11, 2024
I did not find it immediately obvious how to gather the
information needed to fix a missing parent error. Search the
repository for the values needed and present them as part of the
message.

Fixes ingydotnet#617, ingydotnet#415, ingydotnet#600
admorgan added a commit that referenced this issue Jul 22, 2024
I did not find it immediately obvious how to gather the
information needed to fix a missing parent error. Search the
repository for the values needed and present them as part of the
message.

Fixes #617, #415, #600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants