git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] submodule: Add --force option for git submodule update

From
Jens Lehmann <jens.lehmann@web.de>
Date
Mar 30, 2011, 19:05 UTC
Message-ID
<4D937F09.10000@web.de>
In-Reply-To
<4D937B7E.10808@morey-chaisemartin.com>
Am 30.03.2011 20:50, schrieb Nicolas Morey-Chaisemartin:
Show 22 quoted lines
> On 03/30/2011 08:32 PM, Jens Lehmann wrote:
>> Am 30.03.2011 09:56, schrieb Nicolas Morey-Chaisemartin:
> 
>> All looking good up to here. But I wonder if the rest of git-submodule.sh
>> could be changed a bit less invasive ... maybe as simple as this?
>>
>> @@ -458,7 +461,6 @@ cmd_update()
>>
>>  		if test "$subsha1" != "$sha1"
>>  		then
>> -			force=
>>  			if test -z "$subsha1"
>>  			then
>>  				force="-f"
>>
>> Now force will not be cleared and thus contain "-f" if the user provided
>> it on the command line. All tests (including your new ones) are running
>> fine with this simplification ... am I missing something?
> 
> Actually, I don't think this work.
> By doing that, if you run git submodule update without -f, it will set -f when you reached the first submodule not yet checked out ( -z $subsha1 ),
> and the following submodules will be checkout using --force which may throw away changes the user wanted to keep.

You are right, I just came to that conclusion myself ... but with a loop local variable initialized from force on every iteration it should work.

> I know it is very intrusive. The main reason for that is I wanted the -f option to always behave the same (meaning throw away changes),
> whether the submodule is already on the right commit or not.

Hmm, I don't know if that is a good thing to do. People are used to "git submodule update" to only touch those submodule where the HEAD differs from the commit recorded in the superproject (And I often find myself using "-f" if the command didn't succeed without it). But when using "-f" touches other submodules than not using it the user might experience a rather unpleasant surprise, I'm not sure we want to go that way.

> If we accept to drop this and only drop the changes when subsha1 != sha1, the patch can be much sorter by simply keeping the force flags I used and without modifying all the case/while thing.
Yes.
Previous: Nicolas Morey-ChaisemartinNext: Nicolas Morey-Chaisemartin
Message 4 of 9 in “submodule: Add --force option for git submodule update”
  1. submodule: Add --force option for git submodule updateNicolas Morey-Chaisemartin, Mar 30, 2011
  2. Jens LehmannMar 30, 2011
  3. Nicolas Morey-ChaisemartinMar 30, 2011
  4. Jens LehmannMar 30, 2011
  5. Nicolas Morey-ChaisemartinMar 30, 2011
  6. Junio C HamanoMar 30, 2011
  7. Nicolas Morey-ChaisemartinMar 31, 2011
  8. Jens LehmannMar 31, 2011
  9. Nicolas Morey-ChaisemartinMar 31, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.