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