@@ -968,7 +968,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
968
968
}
969
969
970
970
static int stash_patch (struct stash_info * info , struct pathspec ps ,
971
- struct strbuf * out_patch )
971
+ struct strbuf * out_patch , int quiet )
972
972
{
973
973
int ret = 0 ;
974
974
struct strbuf out = STRBUF_INIT ;
@@ -1021,7 +1021,8 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
1021
1021
}
1022
1022
1023
1023
if (!out_patch -> len ) {
1024
- fprintf_ln (stderr , _ ("No changes selected" ));
1024
+ if (!quiet )
1025
+ fprintf_ln (stderr , _ ("No changes selected" ));
1025
1026
ret = 1 ;
1026
1027
}
1027
1028
@@ -1100,7 +1101,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1100
1101
1101
1102
static int do_create_stash (struct pathspec ps , struct strbuf * stash_msg_buf ,
1102
1103
int include_untracked , int patch_mode ,
1103
- struct stash_info * info , struct strbuf * patch )
1104
+ struct stash_info * info , struct strbuf * patch ,
1105
+ int quiet )
1104
1106
{
1105
1107
int ret = 0 ;
1106
1108
int flags = 0 ;
@@ -1120,7 +1122,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1120
1122
refresh_cache (REFRESH_QUIET );
1121
1123
1122
1124
if (get_oid ("HEAD" , & info -> b_commit )) {
1123
- fprintf_ln (stderr , _ ("You do not have the initial commit yet" ));
1125
+ if (!quiet )
1126
+ fprintf_ln (stderr , _ ("You do not have "
1127
+ "the initial commit yet" ));
1124
1128
ret = -1 ;
1125
1129
goto done ;
1126
1130
} else {
@@ -1145,34 +1149,39 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1145
1149
if (write_cache_as_tree (& info -> i_tree , 0 , NULL ) ||
1146
1150
commit_tree (commit_tree_label .buf , commit_tree_label .len ,
1147
1151
& info -> i_tree , parents , & info -> i_commit , NULL , NULL )) {
1148
- fprintf_ln (stderr , _ ("Cannot save the current index state" ));
1152
+ if (!quiet )
1153
+ fprintf_ln (stderr , _ ("Cannot save the current "
1154
+ "index state" ));
1149
1155
ret = -1 ;
1150
1156
goto done ;
1151
1157
}
1152
1158
1153
1159
if (include_untracked && get_untracked_files (ps , include_untracked ,
1154
1160
& untracked_files )) {
1155
1161
if (save_untracked_files (info , & msg , untracked_files )) {
1156
- fprintf_ln (stderr , _ ("Cannot save "
1157
- "the untracked files" ));
1162
+ if (!quiet )
1163
+ fprintf_ln (stderr , _ ("Cannot save "
1164
+ "the untracked files" ));
1158
1165
ret = -1 ;
1159
1166
goto done ;
1160
1167
}
1161
1168
untracked_commit_option = 1 ;
1162
1169
}
1163
1170
if (patch_mode ) {
1164
- ret = stash_patch (info , ps , patch );
1171
+ ret = stash_patch (info , ps , patch , quiet );
1165
1172
if (ret < 0 ) {
1166
- fprintf_ln (stderr , _ ("Cannot save the current "
1167
- "worktree state" ));
1173
+ if (!quiet )
1174
+ fprintf_ln (stderr , _ ("Cannot save the current "
1175
+ "worktree state" ));
1168
1176
goto done ;
1169
1177
} else if (ret > 0 ) {
1170
1178
goto done ;
1171
1179
}
1172
1180
} else {
1173
1181
if (stash_working_tree (info , ps )) {
1174
- fprintf_ln (stderr , _ ("Cannot save the current "
1175
- "worktree state" ));
1182
+ if (!quiet )
1183
+ fprintf_ln (stderr , _ ("Cannot save the current "
1184
+ "worktree state" ));
1176
1185
ret = -1 ;
1177
1186
goto done ;
1178
1187
}
@@ -1198,7 +1207,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1198
1207
1199
1208
if (commit_tree (stash_msg_buf -> buf , stash_msg_buf -> len , & info -> w_tree ,
1200
1209
parents , & info -> w_commit , NULL , NULL )) {
1201
- fprintf_ln (stderr , _ ("Cannot record working tree state" ));
1210
+ if (!quiet )
1211
+ fprintf_ln (stderr , _ ("Cannot record "
1212
+ "working tree state" ));
1202
1213
ret = -1 ;
1203
1214
goto done ;
1204
1215
}
@@ -1233,7 +1244,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
1233
1244
memset (& ps , 0 , sizeof (ps ));
1234
1245
strbuf_addstr (& stash_msg_buf , stash_msg );
1235
1246
ret = do_create_stash (ps , & stash_msg_buf , include_untracked , 0 , & info ,
1236
- NULL );
1247
+ NULL , 0 );
1237
1248
if (!ret )
1238
1249
printf_ln ("%s" , oid_to_hex (& info .w_commit ));
1239
1250
@@ -1295,26 +1306,29 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1295
1306
1296
1307
if (!reflog_exists (ref_stash ) && do_clear_stash ()) {
1297
1308
ret = -1 ;
1298
- fprintf_ln (stderr , _ ("Cannot initialize stash" ));
1309
+ if (!quiet )
1310
+ fprintf_ln (stderr , _ ("Cannot initialize stash" ));
1299
1311
goto done ;
1300
1312
}
1301
1313
1302
1314
if (stash_msg )
1303
1315
strbuf_addstr (& stash_msg_buf , stash_msg );
1304
1316
if (do_create_stash (ps , & stash_msg_buf , include_untracked , patch_mode ,
1305
- & info , & patch )) {
1317
+ & info , & patch , quiet )) {
1306
1318
ret = -1 ;
1307
1319
goto done ;
1308
1320
}
1309
1321
1310
1322
if (do_store_stash (& info .w_commit , stash_msg_buf .buf , 1 )) {
1311
1323
ret = -1 ;
1312
- fprintf_ln (stderr , _ ("Cannot save the current status" ));
1324
+ if (!quiet )
1325
+ fprintf_ln (stderr , _ ("Cannot save the current status" ));
1313
1326
goto done ;
1314
1327
}
1315
1328
1316
- printf_ln (_ ("Saved working directory and index state %s" ),
1317
- stash_msg_buf .buf );
1329
+ if (!quiet )
1330
+ printf_ln (_ ("Saved working directory and index state %s" ),
1331
+ stash_msg_buf .buf );
1318
1332
1319
1333
if (!patch_mode ) {
1320
1334
if (include_untracked && !ps .nr ) {
@@ -1416,7 +1430,9 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1416
1430
argv_array_pushl (& cp .args , "apply" , "-R" , NULL );
1417
1431
1418
1432
if (pipe_command (& cp , patch .buf , patch .len , NULL , 0 , NULL , 0 )) {
1419
- fprintf_ln (stderr , _ ("Cannot remove worktree changes" ));
1433
+ if (!quiet )
1434
+ fprintf_ln (stderr , _ ("Cannot remove "
1435
+ "worktree changes" ));
1420
1436
ret = -1 ;
1421
1437
goto done ;
1422
1438
}
0 commit comments