@@ -15,7 +15,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
1515 "\033[31m" , /* WT_STATUS_CHANGED: red */
1616 "\033[31m" , /* WT_STATUS_UNTRACKED: red */
1717};
18- static const char * use_add_msg = "use \"git add file1 file2 \" to include for commit" ;
18+ static const char * use_add_msg = "use \"git add <file>... \" to incrementally add content to commit" ;
1919
2020static int parse_status_slot (const char * var , int offset )
2121{
@@ -41,8 +41,6 @@ void wt_status_prepare(struct wt_status *s)
4141 unsigned char sha1 [20 ];
4242 const char * head ;
4343
44- s -> is_initial = get_sha1 ("HEAD" , sha1 ) ? 1 : 0 ;
45-
4644 head = resolve_ref ("HEAD" , sha1 , 0 , NULL );
4745 s -> branch = head ? xstrdup (head ) : NULL ;
4846
@@ -51,6 +49,20 @@ void wt_status_prepare(struct wt_status *s)
5149 s -> verbose = 0 ;
5250 s -> commitable = 0 ;
5351 s -> untracked = 0 ;
52+
53+ s -> workdir_clean = 1 ;
54+ }
55+
56+ static void wt_status_print_cached_header (const char * reference )
57+ {
58+ const char * c = color (WT_STATUS_HEADER );
59+ color_printf_ln (c , "# Cached changes to be committed:" );
60+ if (reference ) {
61+ color_printf_ln (c , "# (use \"git reset %s <file>...\" and \"git rm --cached <file>...\" to unstage)" , reference );
62+ } else {
63+ color_printf_ln (c , "# (use \"git rm --cached <file>...\" to unstage)" );
64+ }
65+ color_printf_ln (c , "#" );
5466}
5567
5668static void wt_status_print_header (const char * main , const char * sub )
@@ -147,8 +159,7 @@ static void wt_status_print_updated_cb(struct diff_queue_struct *q,
147159 if (q -> queue [i ]-> status == 'U' )
148160 continue ;
149161 if (!shown_header ) {
150- wt_status_print_header ("Added but not yet committed" ,
151- "will commit" );
162+ wt_status_print_cached_header (s -> reference );
152163 s -> commitable = 1 ;
153164 shown_header = 1 ;
154165 }
@@ -162,9 +173,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
162173 struct diff_options * options ,
163174 void * data )
164175{
176+ struct wt_status * s = data ;
165177 int i ;
166- if (q -> nr )
178+ if (q -> nr ) {
179+ s -> workdir_clean = 0 ;
167180 wt_status_print_header ("Changed but not added" , use_add_msg );
181+ }
168182 for (i = 0 ; i < q -> nr ; i ++ )
169183 wt_status_print_filepair (WT_STATUS_CHANGED , q -> queue [i ]);
170184 if (q -> nr )
@@ -179,8 +193,7 @@ void wt_status_print_initial(struct wt_status *s)
179193 read_cache ();
180194 if (active_nr ) {
181195 s -> commitable = 1 ;
182- wt_status_print_header ("Added but not yet committed" ,
183- "will commit" );
196+ wt_status_print_cached_header (NULL );
184197 }
185198 for (i = 0 ; i < active_nr ; i ++ ) {
186199 color_printf (color (WT_STATUS_HEADER ), "#\t" );
@@ -215,7 +228,7 @@ static void wt_status_print_changed(struct wt_status *s)
215228 run_diff_files (& rev , 0 );
216229}
217230
218- static void wt_status_print_untracked (const struct wt_status * s )
231+ static void wt_status_print_untracked (struct wt_status * s )
219232{
220233 struct dir_struct dir ;
221234 const char * x ;
@@ -250,6 +263,7 @@ static void wt_status_print_untracked(const struct wt_status *s)
250263 continue ;
251264 }
252265 if (!shown_header ) {
266+ s -> workdir_clean = 0 ;
253267 wt_status_print_header ("Untracked files" , use_add_msg );
254268 shown_header = 1 ;
255269 }
@@ -271,6 +285,9 @@ static void wt_status_print_verbose(struct wt_status *s)
271285
272286void wt_status_print (struct wt_status * s )
273287{
288+ unsigned char sha1 [20 ];
289+ s -> is_initial = get_sha1 (s -> reference , sha1 ) ? 1 : 0 ;
290+
274291 if (s -> branch )
275292 color_printf_ln (color (WT_STATUS_HEADER ),
276293 "# On branch %s" , s -> branch );
@@ -291,10 +308,16 @@ void wt_status_print(struct wt_status *s)
291308
292309 if (s -> verbose && !s -> is_initial )
293310 wt_status_print_verbose (s );
294- if (!s -> commitable )
295- printf ("%s (%s)\n" ,
296- s -> amend ? "# No changes" : "nothing to commit" ,
297- use_add_msg );
311+ if (!s -> commitable ) {
312+ if (s -> amend )
313+ printf ("# No changes\n" );
314+ else if (s -> workdir_clean )
315+ printf (s -> is_initial
316+ ? "nothing to commit\n"
317+ : "nothing to commit (working directory matches HEAD)\n" );
318+ else
319+ printf ("no changes added to commit (use \"git add\" and/or \"git commit [-a|-i|-o]\")\n" );
320+ }
298321}
299322
300323int git_status_config (const char * k , const char * v )
0 commit comments