blob: c55a25ca37d2425d398f59c98ff177c8dfa6fdaf [file] [log] [blame]
Johannes Schindelin752c0c22009-10-19 14:38:32 +02001#ifndef SUBMODULE_H
2#define SUBMODULE_H
3
Jeff King873cd282020-07-28 16:23:25 -04004struct strvec;
Elijah Newrenef3ca952018-08-15 10:54:05 -07005struct cache_entry;
6struct diff_options;
7struct index_state;
8struct object_id;
brian m. carlson910650d2017-03-31 01:40:00 +00009struct oid_array;
Elijah Newrenef3ca952018-08-15 10:54:05 -070010struct pathspec;
Brandon Williams06bf4ad2017-04-05 10:47:19 -070011struct remote;
Elijah Newrenef3ca952018-08-15 10:54:05 -070012struct repository;
13struct string_list;
14struct strbuf;
Jens Lehmann46a958b2010-06-25 16:56:47 +020015
Philippe Blain465b30a2022-04-04 17:10:11 +000016enum submodule_recurse_mode {
Brandon Williams6c656c32016-12-19 10:25:32 -080017 RECURSE_SUBMODULES_ONLY = -5,
Mike Croweb33a15b2015-11-17 11:05:56 +000018 RECURSE_SUBMODULES_CHECK = -4,
Heiko Voigt027771f2015-08-17 17:22:00 -070019 RECURSE_SUBMODULES_ERROR = -3,
Heiko Voigt959b5452015-08-17 17:21:57 -070020 RECURSE_SUBMODULES_NONE = -2,
Jens Lehmann88a21972011-03-06 23:10:46 +010021 RECURSE_SUBMODULES_ON_DEMAND = -1,
22 RECURSE_SUBMODULES_OFF = 0,
23 RECURSE_SUBMODULES_DEFAULT = 1,
24 RECURSE_SUBMODULES_ON = 2
25};
26
Stefan Bellerea2fa5a2016-02-29 18:07:11 -080027enum submodule_update_type {
28 SM_UPDATE_UNSPECIFIED = 0,
29 SM_UPDATE_CHECKOUT,
30 SM_UPDATE_REBASE,
31 SM_UPDATE_MERGE,
32 SM_UPDATE_NONE,
33 SM_UPDATE_COMMAND
34};
35
36struct submodule_update_strategy {
37 enum submodule_update_type type;
38 const char *command;
39};
Ævar Arnfjörð Bjarmasonf69a6e42021-09-27 14:54:27 +020040#define SUBMODULE_UPDATE_STRATEGY_INIT { \
41 .type = SM_UPDATE_UNSPECIFIED, \
42}
Stefan Bellerea2fa5a2016-02-29 18:07:11 -080043
Derrick Stolee847a9e52021-04-01 01:49:39 +000044int is_gitmodules_unmerged(struct index_state *istate);
Antonio Ospiteb5c259f2018-10-05 15:05:59 +020045int is_writing_gitmodules_ok(void);
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020046int is_staging_gitmodules_ok(struct index_state *istate);
47int update_path_in_gitmodules(const char *oldpath, const char *newpath);
48int remove_path_from_gitmodules(const char *path);
49void stage_updated_gitmodules(struct index_state *istate);
50void set_diffopt_flags_from_submodule_config(struct diff_options *,
51 const char *path);
52int git_default_submodule_config(const char *var, const char *value, void *cb);
Stefan Bellerd7a38032017-05-26 12:10:12 -070053
54struct option;
55int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
56 const char *arg, int unset);
Glen Choo961b1302022-01-28 16:04:45 -080057int is_tree_submodule_active(struct repository *repo,
58 const struct object_id *treeish_name,
59 const char *path);
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020060int is_submodule_active(struct repository *repo, const char *path);
Stefan Beller15cdc642017-03-14 14:46:31 -070061/*
62 * Determine if a submodule has been populated at a given 'path' by checking if
63 * the <path>/.git resolves to a valid git repository.
64 * If return_error_code is NULL, die on error.
65 * Otherwise the return error code is the same as of resolve_gitdir_gently.
66 */
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020067int is_submodule_populated_gently(const char *path, int *return_error_code);
Derrick Stolee847a9e52021-04-01 01:49:39 +000068void die_in_unpopulated_submodule(struct index_state *istate,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020069 const char *prefix);
Derrick Stolee847a9e52021-04-01 01:49:39 +000070void die_path_inside_submodule(struct index_state *istate,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020071 const struct pathspec *ps);
72enum submodule_update_type parse_submodule_update_type(const char *value);
73int parse_submodule_update_strategy(const char *value,
74 struct submodule_update_strategy *dst);
Ævar Arnfjörð Bjarmasonb9dd63f2022-09-01 01:18:05 +020075const char *submodule_update_type_to_string(enum submodule_update_type type);
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020076void handle_ignore_submodules_arg(struct diff_options *, const char *);
Shourya Shukla180b1542020-08-13 01:14:02 +053077void show_submodule_diff_summary(struct diff_options *o, const char *path,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020078 struct object_id *one, struct object_id *two,
79 unsigned dirty_submodule);
80void show_submodule_inline_diff(struct diff_options *o, const char *path,
81 struct object_id *one, struct object_id *two,
82 unsigned dirty_submodule);
Stefan Beller84f89252017-03-14 14:46:34 -070083/* Check if we want to update any submodule.*/
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020084int should_update_submodules(void);
Stefan Beller84f89252017-03-14 14:46:34 -070085/*
86 * Returns the submodule struct if the given ce entry is a submodule
87 * and it should be updated. Returns NULL otherwise.
88 */
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020089const struct submodule *submodule_from_ce(const struct cache_entry *ce);
90void check_for_new_submodule_commits(struct object_id *oid);
Glen Choob90d9f72022-03-07 16:14:32 -080091int fetch_submodules(struct repository *r,
92 const struct strvec *options,
93 const char *prefix,
94 int command_line_option,
95 int default_option,
96 int quiet, int max_parallel_jobs);
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +020097unsigned is_submodule_modified(const char *path, int ignore_untracked);
98int submodule_uses_gitfile(const char *path);
Stefan Beller83b76962016-12-20 15:20:11 -080099
100#define SUBMODULE_REMOVAL_DIE_ON_ERROR (1<<0)
101#define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1)
102#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +0200103int bad_to_remove_submodule(const char *path, unsigned flags);
Stefan Beller18cfc082018-05-15 13:00:28 -0700104
Jonathan Tana35e03d2021-08-16 14:09:51 -0700105/*
Glen Choo5fff35d2022-03-07 16:14:33 -0800106 * Call add_submodule_odb_by_path() to add the submodule at the given
107 * path to a list. When register_all_submodule_odb_as_alternates() is
108 * called, the object stores of all submodules in that list will be
109 * added as alternates in the_repository.
Jonathan Tana35e03d2021-08-16 14:09:51 -0700110 */
Jonathan Tan8d33c3a2021-08-16 14:09:52 -0700111void add_submodule_odb_by_path(const char *path);
Jonathan Tana35e03d2021-08-16 14:09:51 -0700112int register_all_submodule_odb_as_alternates(void);
Stefan Bellera6d7eb22017-06-23 12:13:02 -0700113
Jonathan Tan4d36f882018-05-24 13:47:29 -0700114/*
115 * Checks if there are submodule changes in a..b. If a is the null OID,
116 * checks b and all its ancestors instead.
117 */
Nguyễn Thái Ngọc Duy6245b982018-10-19 19:34:43 +0200118int submodule_touches_in_range(struct repository *r,
Nguyễn Thái Ngọc Duy174d1312018-09-21 17:57:35 +0200119 struct object_id *a,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +0200120 struct object_id *b);
Nguyễn Thái Ngọc Duy6245b982018-10-19 19:34:43 +0200121int find_unpushed_submodules(struct repository *r,
Nguyễn Thái Ngọc Duy174d1312018-09-21 17:57:35 +0200122 struct oid_array *commits,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +0200123 const char *remotes_name,
124 struct string_list *needs_pushing);
Brandon Williams60fba4b2018-05-16 15:58:23 -0700125struct refspec;
Nguyễn Thái Ngọc Duy6245b982018-10-19 19:34:43 +0200126int push_unpushed_submodules(struct repository *r,
Nguyễn Thái Ngọc Duy174d1312018-09-21 17:57:35 +0200127 struct oid_array *commits,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +0200128 const struct remote *remote,
129 const struct refspec *rs,
130 const struct string_list *push_options,
131 int dry_run);
Nguyễn Thái Ngọc Duybbbb7de2017-03-26 09:42:30 +0700132/*
133 * Given a submodule path (as in the index), return the repository
134 * path of that submodule in 'buf'. Return -1 on error or when the
135 * submodule is not initialized.
136 */
137int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
Johannes Schindelin752c0c22009-10-19 14:38:32 +0200138
Johannes Schindelina8dee3c2019-10-01 23:27:18 +0200139/*
Jonathan Tance125d42021-09-15 11:59:19 -0700140 * Given a submodule name, create a path to where the submodule's gitdir lives
141 * inside of the provided repository's 'modules' directory.
142 */
143void submodule_name_to_gitdir(struct strbuf *buf, struct repository *r,
144 const char *submodule_name);
145
146/*
Johannes Schindelina8dee3c2019-10-01 23:27:18 +0200147 * Make sure that no submodule's git dir is nested in a sibling submodule's.
148 */
149int validate_submodule_git_dir(char *git_dir, const char *submodule_name);
150
Stefan Beller6e3c1592017-03-14 14:46:37 -0700151#define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0)
152#define SUBMODULE_MOVE_HEAD_FORCE (1<<1)
Ævar Arnfjörð Bjarmason4002ec32022-12-20 13:39:56 +0100153int submodule_move_head(const char *path, const char *super_prefix,
154 const char *old_head, const char *new_head,
Nguyễn Thái Ngọc Duy4dcd7062018-06-30 11:20:31 +0200155 unsigned flags);
Stefan Beller6e3c1592017-03-14 14:46:37 -0700156
Stefan Beller898c2e62018-12-14 15:59:43 -0800157void submodule_unset_core_worktree(const struct submodule *sub);
158
Jeff King46387282016-04-28 09:38:20 -0400159/*
Ævar Arnfjörð Bjarmasonb3193252022-06-02 11:09:51 +0200160 * Prepare the "env" parameter of a "struct child_process" for executing
Han-Wen Nienhuys217bb562017-09-21 14:43:37 +0200161 * a submodule by clearing any repo-specific environment variables, but
Jeff King89044ba2016-05-04 21:22:19 -0400162 * retaining any config in the environment.
Jeff King46387282016-04-28 09:38:20 -0400163 */
Ævar Arnfjörð Bjarmasonb3193252022-06-02 11:09:51 +0200164void prepare_submodule_repo_env(struct strvec *env);
Jeff King46387282016-04-28 09:38:20 -0400165
Ævar Arnfjörð Bjarmasonf0a5e5a2022-12-20 13:39:50 +0100166void absorb_git_dir_into_superproject(const char *path,
167 const char *super_prefix);
Stefan Bellerbf0231c2017-03-08 15:07:42 -0800168
169/*
170 * Return the absolute path of the working tree of the superproject, which this
171 * project is a submodule of. If this repository is not a submodule of
Alexandr Miloslavskiy49d3c4b2020-03-10 13:11:24 +0000172 * another repository, return 0.
Stefan Bellerbf0231c2017-03-08 15:07:42 -0800173 */
Alexandr Miloslavskiy49d3c4b2020-03-10 13:11:24 +0000174int get_superproject_working_tree(struct strbuf *buf);
Stefan Bellerbf0231c2017-03-08 15:07:42 -0800175
Johannes Schindelin752c0c22009-10-19 14:38:32 +0200176#endif