git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Yaroslav Halchenko <yoh@onerussian.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: [wishlist] git submodule update --reset-hard
Date: Thu, 6 Dec 2018 12:35:54 -0500
Message-ID: <20181206173554.GH4633@hopa.kiewit.dartmouth.edu> (raw)

Dear Git Gurus,

I wondered what would be your take on my wishlist request to add
--reset-hard option, which would be very similar to regular "update" which
checks out necessary commit, but I want it to remain in the branch.

Rationale: In DataLad we heavily rely on submodules, and we have established
easy ways to do some manipulations across full hierarchies of them. E.g. a
single command could introduce a good number of commits across deep hierarchy
of submodules, e.g. while committing changes within deep submodule, while also
doing all necessary commits in the repositories leading to that submodule so
the entire tree of them stays in a "clean" state. The difficulty comes when
there is a need to just "forget" some changes.  The obvious way is to e.g. 

   git reset --hard PREVIOUS_STATE

in the top level repository.  But that leaves all the submodules now in
the undesired state.  If I do

  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)

Example:

# Have to use datalad install  since  git clone --recurse-submodules
# seems to not consider alternative locations for submodules' .git/
# with url being just a relative path, and where submodules aren't 
# all residing up under toplevel URL .git/

	$> datalad install -r http://datasets.datalad.org/labs/gobbini/.git
	[INFO   ] Cloning http://datasets.datalad.org/labs/gobbini/.git into '/tmp/gobbini' 
	install(ok): /tmp/gobbini (dataset)                                                                             
	[INFO   ] Installing <Dataset path=/tmp/gobbini> recursively 
	[INFO   ] Cloning http://datasets.datalad.org/labs/gobbini/famface/.git into '/tmp/gobbini/famface' 
	[INFO   ] Cloning http://datasets.datalad.org/labs/gobbini/famface/data/.git into '/tmp/gobbini/famface/data'   
	[INFO   ] access to dataset sibling "datasets.datalad.org" not auto-enabled, enable with:                       
	| 		datalad siblings -d "/tmp/gobbini/famface/data" enable -s datasets.datalad.org 
	[INFO   ] Cloning http://datasets.datalad.org/labs/gobbini/famface/data/scripts/mridefacer/.git [2 other candidates] into '/tmp/gobbini/famface/data/scripts/mridefacer' 
	action summary:                                                                                                 
	  install (ok: 4)

so I have a hierarchy in a good state and all checked out in master
branch

	$> cd gobbini

	$> git submodule status --recursive       
	 b9071a6bc9f7665f7c75549c63d29f16d40e8af7 famface (heads/master)
	 e59ba76b42f219bdf14b6b547dd6d9cc0ed5227f famface/data (BIDS-v1.0.1-3-ge59ba76b)
	 5d8036c0aaeebb448a00df6296ddc9f799efdd1f famface/data/scripts/mridefacer (heads/master)

	$> git submodule foreach --recursive cat .git/HEAD                 
	Entering 'famface'
	ref: refs/heads/master
	Entering 'famface/data'
	ref: refs/heads/master
	Entering 'famface/data/scripts/mridefacer'
	ref: refs/heads/master


and if I do roll back

	$> git reset --hard HEAD^^^        
	HEAD is now at 9b4296d [DATALAD] aggregated meta data
	changes on filesystem:                                                                                          
	 famface | 2 +-

and default update --recursive

	$> git submodule update --recursive
	Submodule path 'famface': checked out '2569ab436501a832d35afbbe9cc20ffeb6077eb1'
	Submodule path 'famface/data': checked out 'f1e8c9b8b025c311424283b9711efc6bc906ba2b'
	Submodule path 'famface/data/scripts/mridefacer': checked out '49b0fe42696724c2a8492f999736056e51b77358'

I end up in detached HEADs

	$> git submodule status --recursive 
	 2569ab436501a832d35afbbe9cc20ffeb6077eb1 famface (2569ab4)
	 f1e8c9b8b025c311424283b9711efc6bc906ba2b famface/data (BIDS-v1.0.1)
	 49b0fe42696724c2a8492f999736056e51b77358 famface/data/scripts/mridefacer (49b0fe4)


I do see that there is a "custom command" way to do it via
"submodule.<name>.update" config setting, but that is not easy to use for my
case since all the `<name>` would be different to specify !git reset --hard for
all of them via config option and I could not find any way to "glob" config
(like submodule.*.update).  But in effect that is probably what I need:

	# restarting from a clean state here
	$> git -c submodule.famface.update='!git reset --hard' submodule update --recursive    
	HEAD is now at 2569ab4 [DATALAD] aggregated meta data
	Submodule path 'famface': 'git reset --hard 2569ab436501a832d35afbbe9cc20ffeb6077eb1'
	Submodule path 'famface/data': checked out 'f1e8c9b8b025c311424283b9711efc6bc906ba2b'
	Submodule path 'famface/data/scripts/mridefacer': checked out '49b0fe42696724c2a8492f999736056e51b77358'

	$> git submodule status --recursive                                                
	 2569ab436501a832d35afbbe9cc20ffeb6077eb1 famface (heads/master)
	 f1e8c9b8b025c311424283b9711efc6bc906ba2b famface/data (BIDS-v1.0.1)
	 49b0fe42696724c2a8492f999736056e51b77358 famface/data/scripts/mridefacer (49b0fe4)


Corner cases I see which might make it trickier for a full blown
solution (might be relevant to current state as well for other
strategies):

-  If between those commits we got an additional submodule added (in
   immediate repository or within one of the subdatasets), ideally it
   should also be wiped out

-- 
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 [this message]
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
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=20181206173554.GH4633@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 list mirror (unofficial, 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/

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