git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
From: Yaroslav Halchenko <yoh@onerussian.com>
To: git <git@vger.kernel.org>
Subject: Re: [wishlist] git submodule update --reset-hard
Date: Thu, 6 Dec 2018 20:22:56 -0500
Message-ID: <20181207012256.GR4633@hopa.kiewit.dartmouth.edu> (raw)
In-Reply-To: <CAGZ79kYoGqWW4tv4-caA18SHKe+y2mnDT84AEWVksDtDObLq0g@mail.gmail.com>

Hi Stefan,

Thanks for the dialogue!  Replies are embedded below.

On Thu, 06 Dec 2018, Stefan Beller wrote:
> ...
> > > What if the branch differs from the sha1 recorded in the superproject?

> > git reset --hard  itself is an operation which should be done with some
> > level of competence in doing "the right thing" by calling it.  You
> > can hop branches even in current (without any submodules in question)
> > repository with it and cause as much chaos as you desire.

> Right.

> git reset --hard would the branch (as well as the working tree) to the
> given sha1, which is confusing as submodules get involved.

> The Right Thing as of now is the sha1 as found in the
> superprojects gitlink. But as that can be different from any branch
> in the submodule, we'd rather detach the HEAD to make it
> deterministic.

yeap, makes total sense to be the thing do that by default ;-)

> There was a proposal to "re-attach HEAD" in the submodule, i.e.
> if the branch branch points at the same commit, we don't need
> a detached HEAD, but could go with the branch instead.

if I got the idea right, if we are talking about any branch, it
would also non-deterministic since who knows what left over branch(es)
point to that commit.  Not sure if I would have used that ;)

> > If desired though, a number of prevention mechanisms could be in place (but
> > would require option(s) to overcome) to allow submodule to be reset --hard'ed
> > only when some conditions met (e.g. only to the commit which is among parent
> > commits path of the current branch).  This way wild hops would be prevented,
> > although you might still end up in some feature branch.  But since "reset
> > --hard" itself doesn't have any safe-guards, I do not really think they should
> > be implemented here either.

> So are you looking for
> a) "stay on submodule branch (i.e. HEAD still points at $branch), and
> reset --hard" such that the submodule has a clean index and at that $branch 
> or
> b) "stay on submodule branch (i.e. HEAD still points at $branch), but $branch is
>    set to the gitlink from the superproject, and then a reset --hard
>    will have the worktree set to it as well.

yes!

NB "gitlink" -- just now discovered the thing for me.  Thought it would be
called a  subproject  echoing what git diff/log -p shows for submodule commits.

> (a) is what the referenced submodule.repoLike option implements.

sounds like it indeed, thanks for spelling out

> I'd understand the desire for (b) as well, as it is a "real" hard reset on
> the superproject level, without detaching branches.

yeap

> > >   git reset --hard --recurse-submodules HEAD

> > it does indeed some trick(s) but not all seems to be the ones I desire:

> > 1. Seems to migrate submodule's .git directories into the top level
> > .git/modules

> Ah yes, that happens too. This will help once you want to git-rm
> a submodule and checkout states before and after.

yeap ;-) 

> > > undesirable in the sense of still having local changes (that is what
> > > the above reset with `--recurse` would fix) or changed the branch
> > > state? (i.e. is detached but was on a branch before?)

> > right -- I meant the local changes and indeed reset --recurse-submodules
> > indeed seems to recurse nicely.  Then the undesired effect remaining only
> > the detached HEAD

> For that we may want to revive discussions in
> https://public-inbox.org/git/20170501180058.8063-5-sbeller@google.com/

well, isn't that one requires a branch to be specified in .gitmodules?

> > > >   git submodule update --recursive

> > > > I would end up in the detached HEADs within submodules.

> > > > What I want is to retain current branch they are at (or may be possible
> > > > "were in"? reflog records might have that information)

> > > So something like

> > >   git submodule foreach --recursive git reset --hard

> > > ?

> > not quite  -- this would just kill all local changes within each submodule, not
> > to reset it to the desired state, which wouldn't be specified in such
> > invocation, and is only known to the repo containing it

> With this answer it sounds like you'd want (b) from above.

yeap

> > > You may be interested in
> > > https://public-inbox.org/git/20180927221603.148025-1-sbeller@google.com/
> > > which introduces a switch `submodule.repoLike [ = true]`, which
> > > when set would not detach HEAD in submodules.

> > Thanks! looks interesting -- was there more discussion/activity beyond those 5
> > posts in the thread?

> Unfortunately there was not.

pity

> > This feature might indeed come handy but if I got it right, it is somewhat
> > complimentary to just having submodule update --reset-hard .  E.g.  submodules
> > might be in different branches (if I am not tracking based on branch names), so
> > I would not want a recursive checkout with -b|-B.  But we would indeed benefit
> > from such functionality, since this difficulty of managing branches of
> > submodules I think would be elevated with it! (e.g. in one use case we probably
> > will end up with a few thousands of submodules, and at least 3 branches in each
> > which would need to be in sync, and typically you wouldn't want different
> > branches to be checked out in different submodules)

> > > Can you say more about the first question above:
> > > Would you typically have situations where the
> > > submodule branch is out of sync with the superproject
> > > and how do you deal with that?

> > typically I do not have anything out of sync.  My primary use-case is to
> > "cancel" recent changes in the entire tree of repositories.  I guess for
> > my use case, instead of needing two commands

> >    git reset --hard PREVIOUSPOINT
> >    git submodule update --reset--hard --recursive

> > I wish there was just one

> >    git reset --hard --recursive PREVIOUSPOINT

> Maybe this could learn options like

>   git reset --hard --recursive=hard,keep-branch PREVIOUSPOINT

'keep-branch' (given aforementioned keeping the specified in .gitmodules
branch) might be confusing.  Also what if a submodule already in a
detached HEAD?  IMHO --recursive=hard, and just saying that it would do
"reset --hard", is imho sufficient.  (that is why I like pure
--reset hard   since it doesn't care and neither does anything to the
branch)

> which then could be put into options like

>   git config reset.recurseSubmodules  hard,keep-branch &&
>   # maybe not needed, depending on the exact meaning
>   # of reset.recurseSubmodules:
>   git config submodule.recurse

> and then

>   git reset --hard PREVIOUS

> would do what you'd desire.

you mean

   git reset --hard --recurse-submodules PREVIOUS

in principle overall I would love to have it, besides not sure what
other than 'hard' could be there, and what 'keep-branch' would exactly
do ;-)

> > but I felt that   submodule update   might be a better starting point
> > since it already  provides different modes for update.  If I was even greedier,
> > I would have asked for

> >    git revert --recursive <commit>...
> >    git rebase --recursive [-i] ...

> > which I also frequently desire (could elaborate on the use cases etc).

> These would be nice to have. It would be nice if you'd elaborate on the
> use cases for future reference in the mailing list archive. :-)

ok, will try to do so ;-) In summary: they are just a logical extension
of git support for submodules for anyone actively working with
submodules to keep entire tree in sync.  Then quite often the need for
reverting a specific commit (which also has changes reflected in
submodules) arises.  The same with rebase, especially to trim away some
no longer desired changes reflected in submodules.  

the initial "git submodule update --reset-hard" is pretty much a
crude workaround for some of those cases, so I would just go earlier in
the history, and redo some things, whenever I could just drop or revert
some selected set of commits.

> > NB or --recurse-submodules to avoid confusion with recursive merge
> > strategy?

> ... and sometimes recursing in the file system, c.f. `ls-tree -r`.

ah... so it is only   submodule  command which has --recursive, and the
rest have --recurse-submodules   when talking about recursing into
submodules?

-- 
Yaroslav O. Halchenko
Center for Open Neuroscience     http://centerforopenneuroscience.org
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419
WWW:   http://www.linkedin.com/in/yarik        

  reply index

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 17:35 Yaroslav Halchenko
2018-12-06 18:29 ` Stefan Beller
2018-12-06 21:24   ` Yaroslav Halchenko
2018-12-06 21:55     ` Stefan Beller
2018-12-07  1:22       ` Yaroslav Halchenko [this message]
2018-12-07 21:55         ` Stefan Beller
2018-12-08  2:15           ` Yaroslav Halchenko
2018-12-08  4:21             ` Yaroslav Halchenko
2018-12-10 18:58               ` Stefan Beller
2018-12-10 20:14                 ` Yaroslav Halchenko
2018-12-11  4:08                 ` [PATCH 1/2] submodule: Add --reset-hard option for git submodule update Yaroslav Halchenko
2018-12-11  4:08                   ` [PATCH 2/2] RF+ENH(TST): compare the entire list of submodule status --recursive to stay intact Yaroslav Halchenko
2018-12-12 19:48                     ` Stefan Beller
2018-12-13 16:42                       ` Yaroslav O Halchenko
2018-12-13 20:44                         ` Stefan Beller
2018-12-13 22:43                           ` Yaroslav O Halchenko
2018-12-13 23:58                             ` Stefan Beller
2018-12-14  4:22                               ` Yaroslav O Halchenko

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181207012256.GR4633@hopa.kiewit.dartmouth.edu \
    --to=yoh@onerussian.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox