blob: 64f1ddc9fd9950f7dbe3b0889bf2085111814cec [file] [log] [blame]
Jeff Kingc91f0d92006-09-08 04:05:34 -04001#ifndef STATUS_H
2#define STATUS_H
3
Kristian Høgsbergf26a0012007-09-17 20:06:42 -04004#include <stdio.h>
Junio C Hamano50b7e702009-08-04 23:49:33 -07005#include "string-list.h"
Junio C Hamano23900a92009-08-09 23:08:40 -07006#include "color.h"
SZEDER Gábor7aa9b9b2015-08-20 16:06:27 +02007#include "pathspec.h"
Jeff Hostetlerfd9b5442018-01-09 18:50:16 +00008#include "remote.h"
Kristian Høgsbergf26a0012007-09-17 20:06:42 -04009
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +010010struct repository;
Nguyễn Thái Ngọc Duy81eff272016-04-22 20:01:31 +070011struct worktree;
12
Jeff Kingc91f0d92006-09-08 04:05:34 -040013enum color_wt_status {
Junio C Hamano23900a92009-08-09 23:08:40 -070014 WT_STATUS_HEADER = 0,
Jeff Kingc91f0d92006-09-08 04:05:34 -040015 WT_STATUS_UPDATED,
16 WT_STATUS_CHANGED,
17 WT_STATUS_UNTRACKED,
Chris Parsons950ce2e2008-05-22 08:50:02 -040018 WT_STATUS_NOBRANCH,
Junio C Hamano4d4d5722009-08-05 00:04:51 -070019 WT_STATUS_UNMERGED,
Daniel Knittl-Frank05a59a02010-05-25 15:45:51 +020020 WT_STATUS_LOCAL_BRANCH,
Aleksi Aalto1d282322010-11-18 01:40:05 +020021 WT_STATUS_REMOTE_BRANCH,
22 WT_STATUS_ONBRANCH,
23 WT_STATUS_MAXSLOT
Jeff Kingc91f0d92006-09-08 04:05:34 -040024};
25
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +020026enum untracked_status_type {
Marius Storm-Olsen6c2ce042008-06-05 14:22:56 +020027 SHOW_NO_UNTRACKED_FILES,
28 SHOW_NORMAL_UNTRACKED_FILES,
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +020029 SHOW_ALL_UNTRACKED_FILES
30};
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +020031
Jameson Millereec0f7f2017-10-30 13:21:37 -040032enum show_ignored_type {
33 SHOW_NO_IGNORED,
34 SHOW_TRADITIONAL_IGNORED,
35 SHOW_MATCHING_IGNORED,
36};
37
Jay Soffian37f7a852011-02-19 23:12:29 -050038/* from where does this commit originate */
39enum commit_whence {
40 FROM_COMMIT, /* normal */
41 FROM_MERGE, /* commit came from merge */
42 FROM_CHERRY_PICK /* commit came from cherry-pick */
43};
44
Junio C Hamano50b7e702009-08-04 23:49:33 -070045struct wt_status_change_data {
46 int worktree_status;
47 int index_status;
48 int stagemask;
Jeff Hostetler1ecdecc2016-08-11 10:45:57 -040049 int mode_head, mode_index, mode_worktree;
50 struct object_id oid_head, oid_index;
Nguyễn Thái Ngọc Duy5134ccd2017-12-27 17:18:38 +070051 int rename_status;
52 int rename_score;
53 char *rename_source;
Jens Lehmann9297f77e62010-03-08 13:53:19 +010054 unsigned dirty_submodule : 2;
55 unsigned new_submodule_commits : 1;
Junio C Hamano50b7e702009-08-04 23:49:33 -070056};
57
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -040058enum wt_status_format {
59 STATUS_FORMAT_NONE = 0,
60 STATUS_FORMAT_LONG,
61 STATUS_FORMAT_SHORT,
62 STATUS_FORMAT_PORCELAIN,
Jeff Hostetler1ecdecc2016-08-11 10:45:57 -040063 STATUS_FORMAT_PORCELAIN_V2,
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -040064
65 STATUS_FORMAT_UNSPECIFIED
66};
67
Stephen P. Smith73ba5d72018-09-30 07:12:45 -070068struct wt_status_state {
69 int merge_in_progress;
70 int am_in_progress;
71 int am_empty_patch;
72 int rebase_in_progress;
73 int rebase_interactive_in_progress;
74 int cherry_pick_in_progress;
75 int bisect_in_progress;
76 int revert_in_progress;
77 int detached_at;
78 char *branch;
79 char *onto;
80 char *detached_from;
81 struct object_id detached_oid;
82 struct object_id revert_head_oid;
83 struct object_id cherry_pick_head_oid;
84};
85
Jeff Kingc91f0d92006-09-08 04:05:34 -040086struct wt_status {
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +010087 struct repository *repo;
Jeff Kingc91f0d92006-09-08 04:05:34 -040088 int is_initial;
89 char *branch;
90 const char *reference;
Nguyễn Thái Ngọc Duy15b55ae2013-07-14 15:35:39 +070091 struct pathspec pathspec;
Jeff Kingc91f0d92006-09-08 04:05:34 -040092 int verbose;
93 int amend;
Jay Soffian37f7a852011-02-19 23:12:29 -050094 enum commit_whence whence;
Junio C Hamano37d07f82007-12-12 19:09:16 -080095 int nowarn;
Junio C Hamanod249b092009-08-09 21:59:30 -070096 int use_color;
Matthieu Moy7a76c282014-03-20 13:12:41 +010097 int no_gettext;
Matthieu Moy2556b992013-09-06 19:43:07 +020098 int display_comment_prefix;
Junio C Hamanod249b092009-08-09 21:59:30 -070099 int relative_paths;
100 int submodule_summary;
Jameson Millereec0f7f2017-10-30 13:21:37 -0400101 enum show_ignored_type show_ignored_mode;
Junio C Hamanod249b092009-08-09 21:59:30 -0700102 enum untracked_status_type show_untracked_files;
Jens Lehmann46a958b2010-06-25 16:56:47 +0200103 const char *ignore_submodule_arg;
Aleksi Aalto1d282322010-11-18 01:40:05 +0200104 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
Jeff King4d2292e2012-05-07 15:35:03 -0400105 unsigned colopts;
Jeff King3207a3a2012-05-07 15:44:44 -0400106 int null_termination;
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +0530107 int commit_template;
Jeff Kingd4a6bf12012-05-07 17:09:04 -0400108 int show_branch;
Liam Beguinc1b5d012017-06-17 18:30:51 -0400109 int show_stash;
Matthieu Moy6a964f52013-09-12 12:50:05 +0200110 int hints;
Jeff Hostetlerfd9b5442018-01-09 18:50:16 +0000111 enum ahead_behind_flags ahead_behind_flags;
Ben Pearte8b2dc22018-05-11 15:38:58 +0000112 int detect_rename;
113 int rename_score;
114 int rename_limit;
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -0400115 enum wt_status_format status_format;
Stephen P. Smith73ba5d72018-09-30 07:12:45 -0700116 struct wt_status_state state;
brian m. carlsoncd025992017-03-26 16:01:25 +0000117 unsigned char sha1_commit[GIT_MAX_RAWSZ]; /* when not Initial */
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -0400118
Jürgen Rühle2a3a3c22007-01-10 23:25:03 +0100119 /* These are computed during processing of the individual sections */
Stephen P. Smith6fa90192018-09-05 17:53:27 -0700120 int committable;
Jürgen Rühle2a3a3c22007-01-10 23:25:03 +0100121 int workdir_dirty;
Kristian Høgsberg0f729f22007-09-17 20:06:43 -0400122 const char *index_file;
Kristian Høgsbergf26a0012007-09-17 20:06:42 -0400123 FILE *fp;
Johannes Schindelin367c9882007-11-11 17:35:41 +0000124 const char *prefix;
Junio C Hamano50b7e702009-08-04 23:49:33 -0700125 struct string_list change;
Junio C Hamano76378682009-08-10 00:36:33 -0700126 struct string_list untracked;
Junio C Hamano6cb3f6b2010-04-10 00:11:53 -0700127 struct string_list ignored;
Nguyễn Thái Ngọc Duy6a38ef22013-03-13 19:59:16 +0700128 uint32_t untracked_in_ms;
Jeff Kingc91f0d92006-09-08 04:05:34 -0400129};
130
Brian Malehornd76650b2017-05-15 23:06:49 -0700131size_t wt_status_locate_end(const char *s, size_t len);
Denton Liud540b702019-04-17 11:23:27 +0100132void wt_status_append_cut_line(struct strbuf *buf);
Nguyễn Thái Ngọc Duyfcef9312014-02-17 19:15:31 +0700133void wt_status_add_cut_line(FILE *fp);
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +0100134void wt_status_prepare(struct repository *r, struct wt_status *s);
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -0400135void wt_status_print(struct wt_status *s);
Junio C Hamano76378682009-08-10 00:36:33 -0700136void wt_status_collect(struct wt_status *s);
Stephen P. Smith73ba5d72018-09-30 07:12:45 -0700137void wt_status_collect_free_buffers(struct wt_status *s);
Nguyễn Thái Ngọc Duy78845452018-11-10 06:48:50 +0100138void wt_status_get_state(struct repository *repo,
139 struct wt_status_state *state,
140 int get_detached_from);
Nguyễn Thái Ngọc Duy81eff272016-04-22 20:01:31 +0700141int wt_status_check_rebase(const struct worktree *wt,
142 struct wt_status_state *state);
Nguyễn Thái Ngọc Duyf5d067a2016-04-22 20:01:34 +0700143int wt_status_check_bisect(const struct worktree *wt,
144 struct wt_status_state *state);
Jeff Kingc91f0d92006-09-08 04:05:34 -0400145
Jeff King8dd0ee82013-07-09 20:23:28 -0400146__attribute__((format (printf, 3, 4)))
147void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
148__attribute__((format (printf, 3, 4)))
149void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
Jonathan Niederbecbdae2011-02-25 23:09:41 -0600150
Johannes Schindelin41a5dd62016-10-07 18:08:56 +0200151/* The following functions expect that the caller took care of reading the index. */
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +0100152int has_unstaged_changes(struct repository *repo,
153 int ignore_submodules);
154int has_uncommitted_changes(struct repository *repo,
155 int ignore_submodules);
156int require_clean_work_tree(struct repository *repo,
157 const char *action,
158 const char *hint,
159 int ignore_submodules,
160 int gently);
Johannes Schindelinfd849862016-10-07 18:08:38 +0200161
Jeff Kingc91f0d92006-09-08 04:05:34 -0400162#endif /* STATUS_H */