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