@@ -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 ;
@@ -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
}
@@ -1204,7 +1213,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1204
1213
1205
1214
if (commit_tree (stash_msg_buf -> buf , stash_msg_buf -> len , & info -> w_tree ,
1206
1215
parents , & info -> w_commit , NULL , NULL )) {
1207
- fprintf_ln (stderr , _ ("Cannot record working tree state" ));
1216
+ if (!quiet )
1217
+ fprintf_ln (stderr , _ ("Cannot record "
1218
+ "working tree state" ));
1208
1219
ret = -1 ;
1209
1220
goto done ;
1210
1221
}
@@ -1239,7 +1250,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
1239
1250
memset (& ps , 0 , sizeof (ps ));
1240
1251
strbuf_addstr (& stash_msg_buf , stash_msg );
1241
1252
ret = do_create_stash (ps , & stash_msg_buf , include_untracked , 0 , & info ,
1242
- NULL );
1253
+ NULL , 0 );
1243
1254
1244
1255
if (!ret )
1245
1256
printf_ln ("%s" , oid_to_hex (& info .w_commit ));
@@ -1302,26 +1313,29 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1302
1313
1303
1314
if (!reflog_exists (ref_stash ) && do_clear_stash ()) {
1304
1315
ret = -1 ;
1305
- fprintf_ln (stderr , _ ("Cannot initialize stash" ));
1316
+ if (!quiet )
1317
+ fprintf_ln (stderr , _ ("Cannot initialize stash" ));
1306
1318
goto done ;
1307
1319
}
1308
1320
1309
1321
if (stash_msg )
1310
1322
strbuf_addstr (& stash_msg_buf , stash_msg );
1311
1323
if (do_create_stash (ps , & stash_msg_buf , include_untracked , patch_mode ,
1312
- & info , & patch )) {
1324
+ & info , & patch , quiet )) {
1313
1325
ret = -1 ;
1314
1326
goto done ;
1315
1327
}
1316
1328
1317
1329
if (do_store_stash (& info .w_commit , stash_msg_buf .buf , 1 )) {
1318
1330
ret = -1 ;
1319
- fprintf_ln (stderr , _ ("Cannot save the current status" ));
1331
+ if (!quiet )
1332
+ fprintf_ln (stderr , _ ("Cannot save the current status" ));
1320
1333
goto done ;
1321
1334
}
1322
1335
1323
- printf_ln (_ ("Saved working directory and index state %s" ),
1324
- stash_msg_buf .buf );
1336
+ if (!quiet )
1337
+ printf_ln (_ ("Saved working directory and index state %s" ),
1338
+ stash_msg_buf .buf );
1325
1339
1326
1340
if (!patch_mode ) {
1327
1341
if (include_untracked && !ps .nr ) {
@@ -1422,7 +1436,9 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1422
1436
argv_array_pushl (& cp .args , "apply" , "-R" , NULL );
1423
1437
1424
1438
if (pipe_command (& cp , patch .buf , patch .len , NULL , 0 , NULL , 0 )) {
1425
- fprintf_ln (stderr , _ ("Cannot remove worktree changes" ));
1439
+ if (!quiet )
1440
+ fprintf_ln (stderr , _ ("Cannot remove "
1441
+ "worktree changes" ));
1426
1442
ret = -1 ;
1427
1443
goto done ;
1428
1444
}
0 commit comments