submodule.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef SUBMODULE_H
  2. #define SUBMODULE_H
  3. struct strvec;
  4. struct cache_entry;
  5. struct diff_options;
  6. struct index_state;
  7. struct object_id;
  8. struct oid_array;
  9. struct pathspec;
  10. struct remote;
  11. struct repository;
  12. struct string_list;
  13. struct strbuf;
  14. enum {
  15. RECURSE_SUBMODULES_ONLY = -5,
  16. RECURSE_SUBMODULES_CHECK = -4,
  17. RECURSE_SUBMODULES_ERROR = -3,
  18. RECURSE_SUBMODULES_NONE = -2,
  19. RECURSE_SUBMODULES_ON_DEMAND = -1,
  20. RECURSE_SUBMODULES_OFF = 0,
  21. RECURSE_SUBMODULES_DEFAULT = 1,
  22. RECURSE_SUBMODULES_ON = 2
  23. };
  24. enum submodule_update_type {
  25. SM_UPDATE_UNSPECIFIED = 0,
  26. SM_UPDATE_CHECKOUT,
  27. SM_UPDATE_REBASE,
  28. SM_UPDATE_MERGE,
  29. SM_UPDATE_NONE,
  30. SM_UPDATE_COMMAND
  31. };
  32. struct submodule_update_strategy {
  33. enum submodule_update_type type;
  34. const char *command;
  35. };
  36. #define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
  37. int is_gitmodules_unmerged(const struct index_state *istate);
  38. int is_writing_gitmodules_ok(void);
  39. int is_staging_gitmodules_ok(struct index_state *istate);
  40. int update_path_in_gitmodules(const char *oldpath, const char *newpath);
  41. int remove_path_from_gitmodules(const char *path);
  42. void stage_updated_gitmodules(struct index_state *istate);
  43. void set_diffopt_flags_from_submodule_config(struct diff_options *,
  44. const char *path);
  45. int git_default_submodule_config(const char *var, const char *value, void *cb);
  46. struct option;
  47. int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
  48. const char *arg, int unset);
  49. int is_submodule_active(struct repository *repo, const char *path);
  50. /*
  51. * Determine if a submodule has been populated at a given 'path' by checking if
  52. * the <path>/.git resolves to a valid git repository.
  53. * If return_error_code is NULL, die on error.
  54. * Otherwise the return error code is the same as of resolve_gitdir_gently.
  55. */
  56. int is_submodule_populated_gently(const char *path, int *return_error_code);
  57. void die_in_unpopulated_submodule(const struct index_state *istate,
  58. const char *prefix);
  59. void die_path_inside_submodule(const struct index_state *istate,
  60. const struct pathspec *ps);
  61. enum submodule_update_type parse_submodule_update_type(const char *value);
  62. int parse_submodule_update_strategy(const char *value,
  63. struct submodule_update_strategy *dst);
  64. const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);
  65. void handle_ignore_submodules_arg(struct diff_options *, const char *);
  66. void show_submodule_diff_summary(struct diff_options *o, const char *path,
  67. struct object_id *one, struct object_id *two,
  68. unsigned dirty_submodule);
  69. void show_submodule_inline_diff(struct diff_options *o, const char *path,
  70. struct object_id *one, struct object_id *two,
  71. unsigned dirty_submodule);
  72. /* Check if we want to update any submodule.*/
  73. int should_update_submodules(void);
  74. /*
  75. * Returns the submodule struct if the given ce entry is a submodule
  76. * and it should be updated. Returns NULL otherwise.
  77. */
  78. const struct submodule *submodule_from_ce(const struct cache_entry *ce);
  79. void check_for_new_submodule_commits(struct object_id *oid);
  80. int fetch_populated_submodules(struct repository *r,
  81. const struct strvec *options,
  82. const char *prefix,
  83. int command_line_option,
  84. int default_option,
  85. int quiet, int max_parallel_jobs);
  86. unsigned is_submodule_modified(const char *path, int ignore_untracked);
  87. int submodule_uses_gitfile(const char *path);
  88. #define SUBMODULE_REMOVAL_DIE_ON_ERROR (1<<0)
  89. #define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1)
  90. #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
  91. int bad_to_remove_submodule(const char *path, unsigned flags);
  92. int add_submodule_odb(const char *path);
  93. /*
  94. * Checks if there are submodule changes in a..b. If a is the null OID,
  95. * checks b and all its ancestors instead.
  96. */
  97. int submodule_touches_in_range(struct repository *r,
  98. struct object_id *a,
  99. struct object_id *b);
  100. int find_unpushed_submodules(struct repository *r,
  101. struct oid_array *commits,
  102. const char *remotes_name,
  103. struct string_list *needs_pushing);
  104. struct refspec;
  105. int push_unpushed_submodules(struct repository *r,
  106. struct oid_array *commits,
  107. const struct remote *remote,
  108. const struct refspec *rs,
  109. const struct string_list *push_options,
  110. int dry_run);
  111. /*
  112. * Given a submodule path (as in the index), return the repository
  113. * path of that submodule in 'buf'. Return -1 on error or when the
  114. * submodule is not initialized.
  115. */
  116. int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
  117. /*
  118. * Make sure that no submodule's git dir is nested in a sibling submodule's.
  119. */
  120. int validate_submodule_git_dir(char *git_dir, const char *submodule_name);
  121. #define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0)
  122. #define SUBMODULE_MOVE_HEAD_FORCE (1<<1)
  123. int submodule_move_head(const char *path,
  124. const char *old,
  125. const char *new_head,
  126. unsigned flags);
  127. void submodule_unset_core_worktree(const struct submodule *sub);
  128. /*
  129. * Prepare the "env_array" parameter of a "struct child_process" for executing
  130. * a submodule by clearing any repo-specific environment variables, but
  131. * retaining any config in the environment.
  132. */
  133. void prepare_submodule_repo_env(struct strvec *out);
  134. #define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0)
  135. void absorb_git_dir_into_superproject(const char *path,
  136. unsigned flags);
  137. /*
  138. * Return the absolute path of the working tree of the superproject, which this
  139. * project is a submodule of. If this repository is not a submodule of
  140. * another repository, return 0.
  141. */
  142. int get_superproject_working_tree(struct strbuf *buf);
  143. #endif