@@ -87,6 +87,12 @@ enum show_patch_type {
87
87
SHOW_PATCH_DIFF = 1 ,
88
88
};
89
89
90
+ enum empty_action {
91
+ STOP_ON_EMPTY_COMMIT = 0 , /* output errors and stop in the middle of an am session */
92
+ DROP_EMPTY_COMMIT , /* skip with a notice message, unless "--quiet" has been passed */
93
+ KEEP_EMPTY_COMMIT , /* keep recording as empty commits */
94
+ };
95
+
90
96
struct am_state {
91
97
/* state directory path */
92
98
char * dir ;
@@ -118,6 +124,7 @@ struct am_state {
118
124
int message_id ;
119
125
int scissors ; /* enum scissors_type */
120
126
int quoted_cr ; /* enum quoted_cr_action */
127
+ int empty_type ; /* enum empty_action */
121
128
struct strvec git_apply_opts ;
122
129
const char * resolvemsg ;
123
130
int committer_date_is_author_date ;
@@ -178,6 +185,25 @@ static int am_option_parse_quoted_cr(const struct option *opt,
178
185
return 0 ;
179
186
}
180
187
188
+ static int am_option_parse_empty (const struct option * opt ,
189
+ const char * arg , int unset )
190
+ {
191
+ int * opt_value = opt -> value ;
192
+
193
+ BUG_ON_OPT_NEG (unset );
194
+
195
+ if (!strcmp (arg , "stop" ))
196
+ * opt_value = STOP_ON_EMPTY_COMMIT ;
197
+ else if (!strcmp (arg , "drop" ))
198
+ * opt_value = DROP_EMPTY_COMMIT ;
199
+ else if (!strcmp (arg , "keep" ))
200
+ * opt_value = KEEP_EMPTY_COMMIT ;
201
+ else
202
+ return error (_ ("Invalid value for --empty: %s" ), arg );
203
+
204
+ return 0 ;
205
+ }
206
+
181
207
/**
182
208
* Returns path relative to the am_state directory.
183
209
*/
@@ -1248,11 +1274,6 @@ static int parse_mail(struct am_state *state, const char *mail)
1248
1274
goto finish ;
1249
1275
}
1250
1276
1251
- if (is_empty_or_missing_file (am_path (state , "patch" ))) {
1252
- printf_ln (_ ("Patch is empty." ));
1253
- die_user_resolve (state );
1254
- }
1255
-
1256
1277
strbuf_addstr (& msg , "\n\n" );
1257
1278
strbuf_addbuf (& msg , & mi .log_message );
1258
1279
strbuf_stripspace (& msg , 0 );
@@ -1763,6 +1784,7 @@ static void am_run(struct am_state *state, int resume)
1763
1784
while (state -> cur <= state -> last ) {
1764
1785
const char * mail = am_path (state , msgnum (state ));
1765
1786
int apply_status ;
1787
+ int to_keep ;
1766
1788
1767
1789
reset_ident_date ();
1768
1790
@@ -1792,8 +1814,29 @@ static void am_run(struct am_state *state, int resume)
1792
1814
if (state -> interactive && do_interactive (state ))
1793
1815
goto next ;
1794
1816
1817
+ to_keep = 0 ;
1818
+ if (is_empty_or_missing_file (am_path (state , "patch" ))) {
1819
+ switch (state -> empty_type ) {
1820
+ case DROP_EMPTY_COMMIT :
1821
+ say (state , stdout , _ ("Skipping: %.*s" ), linelen (state -> msg ), state -> msg );
1822
+ goto next ;
1823
+ break ;
1824
+ case KEEP_EMPTY_COMMIT :
1825
+ to_keep = 1 ;
1826
+ say (state , stdout , _ ("Creating an empty commit: %.*s" ),
1827
+ linelen (state -> msg ), state -> msg );
1828
+ break ;
1829
+ case STOP_ON_EMPTY_COMMIT :
1830
+ printf_ln (_ ("Patch is empty." ));
1831
+ die_user_resolve (state );
1832
+ break ;
1833
+ }
1834
+ }
1835
+
1795
1836
if (run_applypatch_msg_hook (state ))
1796
1837
exit (1 );
1838
+ if (to_keep )
1839
+ goto commit ;
1797
1840
1798
1841
say (state , stdout , _ ("Applying: %.*s" ), linelen (state -> msg ), state -> msg );
1799
1842
@@ -1827,6 +1870,7 @@ static void am_run(struct am_state *state, int resume)
1827
1870
die_user_resolve (state );
1828
1871
}
1829
1872
1873
+ commit :
1830
1874
do_commit (state );
1831
1875
1832
1876
next :
@@ -2357,6 +2401,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2357
2401
{ OPTION_STRING , 'S' , "gpg-sign" , & state .sign_commit , N_ ("key-id" ),
2358
2402
N_ ("GPG-sign commits" ),
2359
2403
PARSE_OPT_OPTARG , NULL , (intptr_t ) "" },
2404
+ OPT_CALLBACK_F (STOP_ON_EMPTY_COMMIT , "empty" , & state .empty_type , "{stop,drop,keep}" ,
2405
+ N_ ("how to handle empty patches" ),
2406
+ PARSE_OPT_NONEG , am_option_parse_empty ),
2360
2407
OPT_HIDDEN_BOOL (0 , "rebasing" , & state .rebasing ,
2361
2408
N_ ("(internal use for git-rebase)" )),
2362
2409
OPT_END ()
0 commit comments