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

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

From
Nicolas Morey-Chaisemartin <devel-git@morey-chaisemartin.com>
Date
Mar 30, 2011, 18:50 UTC
Message-ID
<4D937B7E.10808@morey-chaisemartin.com>
In-Reply-To
<4D93773C.2010807@web.de>
On 03/30/2011 08:32 PM, Jens Lehmann wrote:
> Am 30.03.2011 09:56, schrieb Nicolas Morey-Chaisemartin:
Show 15 quoted lines
> 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.

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.

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.
Show 27 quoted lines
>>  
>> +test_expect_success 'submodule update should fail due to local changes' '
>> +	(cd super/submodule &&
>> +	 git reset --hard HEAD~1 &&
>> +	 echo "local change" > file
>> +	) &&
>> +	(cd super &&
>> +	 (cd submodule &&
>> +	  compare_head
>> +	 ) &&
>> +	 test_must_fail git submodule update submodule
>> +	)
>> +'
> 
> This test is shorter and might be easier to understand rewritten as:
> 
> +test_expect_success 'submodule update should fail due to local changes' '
> +	(cd super &&
> +	 (cd submodule &&
> +	  git reset --hard HEAD~1 &&
> +	  echo "local change" > file
> +	  compare_head
> +	 ) &&
> +	 test_must_fail git submodule update submodule
> +	)
> +'
> 
Agreed.
Previous: Jens LehmannNext: Jens Lehmann
Message 3 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.