[PATCH] localrepo: abort commit if a subrepo is modified and ui.commitsubs=no

Mads Kiilerich mads at kiilerich.com
Sun Feb 13 20:09:36 CST 2011


Patrick Mezard wrote, On 02/12/2011 06:00 PM:
> # HG changeset patch
> # User Patrick Mezard<pmezard at gmail.com>
> # Date 1297528291 -3600
> # Node ID c144bfef2727616001b3c7fa6fd1db8049188497
> # Parent  d4ab9486e514dd24e21a2ca3b6c439ea13d85cab
> localrepo: abort commit if a subrepo is modified and ui.commitsubs=no
>
> The default behaviour is to commit subrepositories with uncommitted changes. In
> my experience this is usually undesirable:
>
> - Changes to dependencies are often debugging leftovers
> - Real changes should generally be applied on the source project directly,
>    tested then committed. This is not always possible, subversion subrepos may
>    include only a small part of the source project, without the tests.
>
> Setting ui.commitsubs=no will now abort commits containing such modified
> subrepositories like:
>
>    $ hg --config ui.commitsubs=no ci -m msg
>    abort: uncommitted changes in subrepo sub

+1

We don't use the abbreviation "subs" in other places, so I think 
"commitsubrepos" would be better even though it is a bit long.

This new setting should perhaps be mentioned in the subrepo help topic too.


But do this setting really belong as a config setting? It is a setting 
that all users of a given subrepo should agree on, so it seems like it 
would be better to store it for example in .hgsub .


Actually I like this setting so much that I would like to have it set to 
False by default.

I still haven't seen any good subrepo use cases where recursive commit 
was an advantage. I can only see the benefit of recursive commit (and 
"invisible" subrepos in general) if subrepos are used as bad workarounds 
for the lack of narrow and shallow clones in Mercurial. I hope we 
eventually will get a real and good solution to the need for flexible 
cloning and don't have to optimize subrepos for that use case.

/Mads


> diff -r d4ab9486e514 -r c144bfef2727 doc/hgrc.5.txt
> --- a/doc/hgrc.5.txt	Thu Feb 10 13:46:28 2011 -0600
> +++ b/doc/hgrc.5.txt	Sat Feb 12 17:31:31 2011 +0100
> @@ -876,6 +876,11 @@
>       be prompted to enter a username. If no username is entered, the
>       default ``USER at HOST`` is used instead.
>       Default is False.
> +``commitsubs``
> +    Whether to commit modified subrepositories when committing the
> +    parent repository. If False and one subrepository has uncommitted
> +    changes, abort the commit.
> +    Default is True.
>   ``debug``
>       Print debugging information. True or False. Default is False.
>   ``editor``
> diff -r d4ab9486e514 -r c144bfef2727 mercurial/localrepo.py
> --- a/mercurial/localrepo.py	Thu Feb 10 13:46:28 2011 -0600
> +++ b/mercurial/localrepo.py	Sat Feb 12 17:31:31 2011 +0100
> @@ -925,6 +925,12 @@
>                   if '.hgsubstate' not in changes[0]:
>                       changes[0].insert(0, '.hgsubstate')
>
> +            if subs and not self.ui.configbool('ui', 'commitsubs', True):
> +                changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
> +                if changedsubs:
> +                    raise util.Abort(_("uncommitted changes in subrepo %s")
> +                                     % changedsubs[0])
> +
>               # make sure all explicit patterns are matched
>               if not force and match.files():
>                   matched = set(changes[0] + changes[1] + changes[2])
> diff -r d4ab9486e514 -r c144bfef2727 tests/test-subrepo.t
> --- a/tests/test-subrepo.t	Thu Feb 10 13:46:28 2011 -0600
> +++ b/tests/test-subrepo.t	Sat Feb 12 17:31:31 2011 +0100
> @@ -75,16 +75,19 @@
>     commit: (clean)
>     update: (current)
>
> -bump sub rev
> +bump sub rev (and check it is ignored by ui.commitsubs)
>
>     $ echo b>  s/a
>     $ hg -R s ci -ms1
> -  $ hg ci -m3
> +  $ hg --config ui.commitsubs=no ci -m3
>     committing subrepository s
>
> -leave sub dirty
> +leave sub dirty (and check ui.commitsubs=no aborts the commit)
>
>     $ echo c>  s/a
> +  $ hg --config ui.commitsubs=no ci -m4
> +  abort: uncommitted changes in subrepo s
> +  [255]
>     $ hg ci -m4
>     committing subrepository s
>     $ hg tip -R s
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list