Skip to content

fix(snap), add the current checked out version as the parent, not the head #9345

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

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

davidfirst
Copy link
Member

@davidfirst davidfirst commented Dec 3, 2024

It's easier to explain this with an example: comp1 has 3 versions: 0.0.1, 0.0.2 and 0.0.3. The head points to 0.0.3. This workspace has comp1 checked out to 0.0.2. The user is now running bit snap.

What should be the parent of this new snap? the checked out version - 0.0.2 or the head - 0.0.3?
Until now, we used the head. In terms of the history, this is incorrect, because it skips the changes done on 0.0.3.
In practice, this is very confusing in the following scenario:
The user now regrets making this snap and to remove it, he/she is running bit reset. Because this snap was on top of the head, the reset changes the .bitmap version to the head version - 0.0.3 while leaving the files in the filesystem according to 0.0.2. The user continues and runs bit snap again. Now, the changes done in 0.0.3 are gone. Investigating when these changes are gone, leads to this new snap, which shows it removes the changes. The user made this snap is not aware of all of this.

This PR fixes it by using the checked out version as the parent. This leads to a component being diverged, because on the remote went to another direction since this checked out version. Once the user tries to export, it'll throw an error suggesting to either bit merge or bit reset and snap again.

@davidfirst davidfirst enabled auto-merge (squash) December 4, 2024 14:45
@davidfirst davidfirst merged commit 14eada6 into master Dec 4, 2024
11 checks passed
@davidfirst davidfirst deleted the fix-history-detached-head branch December 4, 2024 15:04
davidfirst added a commit that referenced this pull request Dec 18, 2024
In some scenarios, it's needed to maintain some legacy code, for
example, the new code is 2.x and the legacy is 1.x which still needs to
be maintained.
If a patch is needed to 1.x code, the component needs to be checked out
to 1.x and tagged with a specific version, for example: `bit tag --ver
1.0.1 --ignore-newest-version`.
Currently, when this patch is done, although the history of this patch
is correct thanks to a recent
[PR](#9345), but the head now points
to this patch version. As a result, when importing the component, the
user gets 1.0.1 and not 2.x.
This PR introduces a new flag `--detach-head` to keep the head intact in
this case, so the head still points to 2.x, while the .bitmap is updated
to 1.0.1. This new patch 1.0.1 becomes a detached head.

It also supports lanes. It's possible to work on multiple components
when they're checked out to 1.x, create a new lane, snap some changes,
then merge the lane with `--detach-head` flag. This flag, instruct bit
to find the common snap before the divergent point, and merge the lane
to that point and not to the head.

In order for the garbage collector to not delete this detached-head
snap, and for the remote to not identify this component as a
merge-conflict, we save a new prop `detachedHeads` into `ModelComponent`
object.

For now, this flag `--detach-head` is under a feature-flag. It'll be
enabled by default once bit cloud is deployed with a new version that
supports it.
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

Successfully merging this pull request may close these issues.

2 participants