ingydotnet / git-subrepo

MIT License
3.24k stars 268 forks source link

Allow merging subrepos #223

Closed jmatsushita closed 7 years ago

jmatsushita commented 8 years ago

Hi there,

(I'm using issue/142 branch). I thought maybe my request was related to #197 but I can't figure it out so I might be having a different (and simpler) problem. I'm sharing my thought process and attempts so that maybe it can be helpful to improve the user experience for less git-savvy users like me.

I'm trying to do a merge in a child repo from a parent repo.

If I was not in a subrepo I would do

git clone git@child child
cd child
git branch -b my_feature
<work>
git commit -am "I worked!"
git push origin my_feature
<review>
git checkout master
git merge my_feature
git push

No trying to do the same thing from a parent subrepo I would do

git clone git@parent parent
cd parent
git subrepo clone git@child child
cd child
<work>
git commit -am "I worked!"
cd ..
git subrepo push -b my_feature child
<review>
<stares blankly in space>

I would expect to do something like git subrepo checkout -b master child and git subrepo merge -b my_feature child to mimick the workflow I'm used to.

I've tried

git subrepo pull -b master child

But this fails because it can't find a common ancestor.

If I do

git subrepo clone --force -b master git@child
git subrepo pull -b master child

This yields git-subrepo: Command failed: 'git checkout -B subrepo/child 13fcda... and leaves my parent repo in a mess - Would be great if git subrepo clean just reverted to before the interrupted command #178, or actually even better just subrepo commands never left the tree in a scary state like that. Currently I do:

git reset HEAD .
git checkout -- .
git clean -df .

So, back to merging I now try another approach thinking I should create a my_feature branch in the parent repo instead:

git clone git@parent parent
cd parent
git subrepo clone git@child child
cd child
git checkout -b my_feature
<work>
git commit -am "I worked!"
cd ..
git subrepo push -b my_feature child
<review>
git checkout master
git merge my_feature
<this yields a reassuring fast-forward message>
git subrepo push -b master child

This fails with git-subrepo: There are new changes upstream, you need to pull first.

If I then try

git subrepo pull -b master child

I get git-subrepo: Can't branch: 'refs/subrepo/child/fetch' doesn't contain dcff64fafc...

Is it the case that I'm both missing something obvious and that the UX is somewhat helping to lead me astray :)

grimmySwe commented 8 years ago

Lets see if I can help you with this. With subrepo you can't really merge only the subrepo. If you want to merge the actual subrepo content you need to work with the subrepo as a regular repo.

What you can do is creating a branch in your parent repo, clone in contents from another branch and then merge the parent repo branches. Then you can push the result of that into the subrepo, note that you will NOT get the merge marked correctly in the subrepo. So if someone checks out the subrepo standalone there will be no hints of the merge.

jmatsushita commented 8 years ago

Ok it does make sense! That's a feature request then :)

grimmySwe commented 7 years ago

@jmatsushita I don't see that this will be implemented in a reasonable future so I close it.