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

Re: [PATCH 10/16] update submodules: is_submodule_checkout_safe

From
BWBrandon Williams <bmwill@google.com>
Date
Nov 16, 2016, 00:06 UTC
Message-ID
<20161116000621.GG66382@google.com>
In-Reply-To
<20161115230651.23953-11-sbeller@google.com>
On 11/15, Stefan Beller wrote:
Show 32 quoted lines
> In later patches we introduce the options and flag for commands
> that modify the working directory, e.g. git-checkout.
> 
> This piece of code will answer the question:
> "Is it safe to change the submodule to this new state?"
> e.g. is it overwriting untracked files or are there local
> changes that would be overwritten?
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  submodule.c | 22 ++++++++++++++++++++++
>  submodule.h |  2 ++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/submodule.c b/submodule.c
> index 2773151..2149ef7 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1201,6 +1201,28 @@ int ok_to_remove_submodule(const char *path)
>  	return ok_to_remove;
>  }
>  
> +int is_submodule_checkout_safe(const char *path, const struct object_id *oid)
> +{
> +	struct child_process cp = CHILD_PROCESS_INIT;
> +
> +	if (!is_submodule_populated(path))
> +		/* The submodule is not populated, it's safe to check it out */
> +		/*
> +		 * TODO: When git learns to re-populate submodules, a check must be
> +		 * added here to assert that no local files will be overwritten.
> +		 */

When you mean local files do you mean in the situation where we want to checkout a submodule at path 'foo' but there already exists a file at path 'foo'?

Show 31 quoted lines
> +		return 1;
> +
> +	argv_array_pushl(&cp.args, "read-tree", "-n", "-m", "HEAD",
> +			 sha1_to_hex(oid->hash), NULL);
> +
> +	prepare_submodule_repo_env(&cp.env_array);
> +	cp.git_cmd = 1;
> +	cp.no_stdin = 1;
> +	cp.dir = path;
> +	return run_command(&cp) == 0;
> +}
> +
>  static int find_first_merges(struct object_array *result, const char *path,
>  		struct commit *a, struct commit *b)
>  {
> diff --git a/submodule.h b/submodule.h
> index f01f87c..a7fa634 100644
> --- a/submodule.h
> +++ b/submodule.h
> @@ -74,6 +74,8 @@ extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
>  extern int is_submodule_populated(const char *path);
>  extern int submodule_uses_gitfile(const char *path);
>  extern int ok_to_remove_submodule(const char *path);
> +extern int is_submodule_checkout_safe(const char *path,
> +				      const struct object_id *oid);
>  extern int merge_submodule(unsigned char result[20], const char *path,
>  			   const unsigned char base[20],
>  			   const unsigned char a[20],
> -- 
> 2.10.1.469.g00a8914
> 
-- 
Brandon Williams
Previous: Stefan BellerNext: Stefan Beller
Message 44 of 50 in “Checkout aware of Submodules!”
  1. 00/16 Checkout aware of Submodules!Stefan Beller, Nov 15, 2016
  2. 01/16 submodule.h: add extern keyword to functions, break line before 80Stefan Beller, Nov 15, 2016
  3. Junio C HamanoNov 16, 2016
  4. Stefan BellerNov 17, 2016
  5. 06/16 update submodules: add a config option to determine if submodules are updatedStefan Beller, Nov 15, 2016
  6. 08/16 update submodules: add depopulate_submoduleStefan Beller, Nov 15, 2016
  7. Brandon WilliamsNov 15, 2016
  8. Stefan BellerNov 17, 2016
  9. Brandon WilliamsNov 17, 2016
  10. Stefan BellerNov 17, 2016
  11. Stefan BellerNov 18, 2016
  12. Brandon WilliamsNov 18, 2016
  13. Stefan BellerNov 18, 2016
  14. 11/16 teach unpack_trees() to remove submodule contentsStefan Beller, Nov 15, 2016
  15. Brandon WilliamsNov 16, 2016
  16. 09/16 update submodules: add scheduling to update submodulesStefan Beller, Nov 15, 2016
  17. Brandon WilliamsNov 16, 2016
  18. David TurnerNov 16, 2016
  19. Stefan BellerNov 18, 2016
  20. 12/16 entry: write_entry to write populate submodulesStefan Beller, Nov 15, 2016
  21. 14/16 checkout: recurse into submodules if asked toStefan Beller, Nov 15, 2016
  22. Brandon WilliamsNov 16, 2016
  23. David TurnerNov 16, 2016
  24. David TurnerNov 16, 2016
  25. 13/16 submodule: teach unpack_trees() to update submodulesStefan Beller, Nov 15, 2016
  26. David TurnerNov 16, 2016
  27. Stefan BellerNov 18, 2016
  28. David TurnerNov 21, 2016
  29. Brandon WilliamsNov 16, 2016
  30. Stefan BellerNov 18, 2016
  31. 16/16 checkout: add config option to recurse into submodules by defaultStefan Beller, Nov 15, 2016
  32. 07/16 update submodules: introduce submodule_is_interestingStefan Beller, Nov 15, 2016
  33. Brandon WilliamsNov 15, 2016
  34. David TurnerNov 16, 2016
  35. Stefan BellerNov 17, 2016
  36. 03/16 submodule: use absolute path for computing relative path connectingStefan Beller, Nov 15, 2016
  37. 04/16 update submodules: add is_submodule_populatedStefan Beller, Nov 15, 2016
  38. Brandon WilliamsNov 15, 2016
  39. 02/16 submodule: modernize ok_to_remove_submodule to use argv_arrayStefan Beller, Nov 15, 2016
  40. David TurnerNov 15, 2016
  41. Junio C HamanoNov 16, 2016
  42. Stefan BellerNov 17, 2016
  43. 10/16 update submodules: is_submodule_checkout_safeStefan Beller, Nov 15, 2016
  44. Brandon WilliamsNov 16, 2016
  45. 05/16 update submodules: add submodule config parsingStefan Beller, Nov 15, 2016
  46. 15/16 completion: add '--recurse-submodules' to checkoutStefan Beller, Nov 15, 2016
  47. Xiaodong QiDec 3, 2016
  48. Stefan BellerNov 17, 2016
  49. Stefan BellerNov 17, 2016
  50. Stefan BellerNov 18, 2016

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.