-
Notifications
You must be signed in to change notification settings - Fork 57
Importing projects with external continuity #596
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
Comments
Good that you ask. This exact use case is supposed to be one of the main selling points of josh and shame on us for not documenting it better. Hope that helps. |
Thanks, I'll try this and contribute the missing docs page for it once I've got it figured out.
Shouldn't a merge of a full history using Might be misunderstanding this point :) |
It does not mean rewriting only future commits. It means applying the backwards transform of |
Okay, understood. I tried it the way you described and it works! 💯 |
Hmm this seems to be true for some of the imported repos. However, with others the checkouts from the subpath have totally different shas than the upstream. They were all imported in precisely the same way (it was a script in a loop), so I know that the method didn't vary. Is this a bug or a caveat I don't understand? |
According to my commit from back then, things were pretty simple. The repository I imported was https://github.com/google/nixery (which has since moved to my Github). I cloned that repo and ran I then merged this commit into the monorepo. Ever since then the commits are exported back to Github (without force-pushing, so the history is compatible) from the monorepo on every change. We configured that in this commit (the |
As I did, with The latter didn't seem to work for me and the former seems to have preserved history for 2 out of 4 repositories: For ❯ cd $src; git clone $josh/$monorepo:/$prefix.git ${prefix}-from-mono
❯ git --git-dir=./$prefix-from-mono/.git log -n1 HEAD --format=format:%H
7efedb2dde6ed9c92094f982ebaaee23e39ac731 Bump braces from 3.0.2 to 3.0.3 in /submit (#317)
❯ cd $src; git clone https://github.com/$subrepo ${prefix}-from-orig && cd ${prefix}-from-origin
❯ git --git-dir=./$prefix-from-origin/.git log -n1 HEAD --format=format:%H
7efedb2dde6ed9c92094f982ebaaee23e39ac731 Bump braces from 3.0.2 to 3.0.3 in /submit (#317) Yet, for for ❯ cd $src; git clone $josh/$monorepo:/$prefix.git ${prefix}-from-mono
❯ git --git-dir=./$prefix-from-mono/.git log -n1 HEAD --format=format:%H
6b2011704fd5da24db146129c71b34b2571e962f Update package caches
❯ cd $src; git clone https://github.com/$subrepo ${prefix}-from-orig && cd ${prefix}-from-origin
❯ git --git-dir=./$prefix-from-origin/.git log -n1 HEAD --format=format:%H
4e43fc04145f9f7e1c371ce48e4f8a624598f0cd Update package caches Both of these repos were created in loop (changing the ❯ cd $src && git clone $josh/$subrepo:prefix=$prefix.git ${prefix}-prefixed && cd ${prefix}-prefixed
❯ git push -o merge -f $josh/$monorepo The |
This is very cool, btw. I stumbled across this a few weeks ago while learning about and playing with Nix, and this is such a slick concept. |
I created a merge commit, I believe with unrelated histories. In what way does that not work for you?
Can you check if there are any commits with GPG signatures in the histories that didn't get preserved cleanly? I remember something related to that, will try to dig it out. |
Yeah there are definitely GPG-signed commits in one of the repos which didn't preserve SHAs. They are broken, as I would expect, but I'll have to look a bit more closely tomorrow as I think there would be GPG-signed commits in the ones which did preserve SHAs too.
When I pushed it back up, it just created broken merge commits and showed a completely flat history in GitHub. However, I just did a test again and realised this might only be true when I push up the monorepo via Josh. If I push the created monorepo directly to GitHub, the merge commits seem intact. I used this script to re-create the monorepo just now: mkdir monorepo && cd monorepo && git init && touch README && git add . && git commit -m "Start monorepo"
for rp in {prefix1:user/subrepo1,prefix2:user/subrepo2}; do
IFS=':' read prefix subrepo <<< $rp
origin="$josh/$subrepo:prefix=$prefix.git"
git remote add $prefix $origin || git remote set-url $prefix $origin
git fetch $prefix main
git merge --allow-unrelated -m "Merge $prefix subrepo" FETCH_HEAD main
done If I push It's late here in my timezone, so more testing tomorrow may be required. I'll re-do this from scratch, push via GitHub, then try cloning a subrepo from that via JOSH and see if the SHAs are intact in all cases. However, I am not hopeful, given the way that I tried it earlier did preserve SHAs in some cases, but not in all. Perhaps the GPG issue or some other non-reversible aspect of the commit content is at fault here. Maybe I can write a script to compare the histories of the two repos and see if there is a specific commit where the history diverged and the SHAs changed, as the content of that commit might yield some clues. |
Oh, I haven't tried to push back a merge through josh. That might cause issues. We don't use Github, and I'm not sure what "When I pushed it back up, it just created broken merge commits" means (why does pushing create new commits?), but I'd expect you'd have to push the raw repo after creating the merge locally. As for the signatures, there's a filter called |
Yeah that wasn't very clear. What I mean is that locally the commit which merges the subrepo in is indeed a merge commit with 2 parents. On GitHub, that same commit only lists one parent and all files in the repo are seen as introduced directly by that commit. The only parent it has is the monorepo root commit (or the previous merge for another subrepo). I am wondering if what is happening here is pushing through JOSH is corrupting that merge in some way or is rewriting the commits the merge parents points to without rewriting the merge commit to point to the new (rewritten) parent. In other words, one of the two parents points to an unresolvable commit, so GitHub just treats it as non-merge commit.
That is extremely good to know. I am not sure whether I'd want this or not, but it's something to experiment with. |
OK looking at this again today: mkdir monorepo && cd monorepo && git init && touch README && git add . && git commit -m "Start monorepo"
for rp in {prefix1:user/subrepo1,prefix2:user/subrepo2,...}; do
IFS=':' read prefix subrepo <<< $rp
import_origin="$josh/$subrepo:prefix=$prefix.git"
git remote add $prefix $import_origin
git fetch $prefix main HEAD
git merge --allow-unrelated -m "Merge $prefix subrepo" FETCH_HEAD main
done This is nicer than the approach I took initially, but is ending up with the same outcome. Changing to However, surprisingly, they are consistent for 7 years of the commit history and then suddenly they diverge only 2 weeks ago: This is not a signed commit and nothing in particular stands out about it. Any ideas of what I could explore to explain this divergence. It seems like it's possibly a JOSH bug a la #1345. |
Diff the raw commit objects, diff their raw tree objects etc. and see what is different, might give us a clue! |
Great idea. I didn't think about Anyway, it seems this is squarely a GitButler thing: ❯ diff <(git show --pretty=raw 8f49df1dc) <(git show --pretty=raw 34d061bdc)
1c1
< commit 8f49df1dc0acf9389c7aa712847cc8309f01755d
---
> commit 34d061bdca18e243ccc8bfe53333037ce17500f9
6,7d5
< gitbutler-headers-version 2
< gitbutler-change-id baefc019-8ef0-40f2-9f1f-dc92b9984387 It seems to be adding its own headers. |
I think at this point this is becoming off-topic, though. It's no longer about clarification on how to import projects with external continuity. I'll open a new issue. |
I've been trying to figure out if there is a way to import an external project into a subtree and keep history continous for external consumers of that repo (i.e. let
git pull
work with a new josh-backed upstream on old checkouts). Ideally all commit hashes would also be preserved.I've tried a couple of things, such as:
HEAD
, push back to josh with-o create
. This creates a history where all the original commits are rebased on the history of the repository, in which case pulling is possible as long as rebasing on pulling is enabled.This is as close as I've gotten to doing what I want, but it loses all the original commit IDs, which is not ideal.
-o create
. Josh flattens the merge commit and original history is lost.What I sort of expected: In the first version, I expected the push back to synthesize a merge commit with the original history instead of rebasing the commits on top of it.
Any ideas on how to accomplish this? If we figure it out I'll contribute some docs for it.
The text was updated successfully, but these errors were encountered: