@@ -973,7 +973,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
973973}
974974
975975static int stash_patch (struct stash_info * info , struct pathspec ps ,
976- struct strbuf * out_patch )
976+ struct strbuf * out_patch , int quiet )
977977{
978978 int ret = 0 ;
979979 struct strbuf out = STRBUF_INIT ;
@@ -1026,7 +1026,8 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
10261026 }
10271027
10281028 if (!out_patch -> len ) {
1029- fprintf_ln (stderr , _ ("No changes selected" ));
1029+ if (!quiet )
1030+ fprintf_ln (stderr , _ ("No changes selected" ));
10301031 ret = 1 ;
10311032 }
10321033
@@ -1104,7 +1105,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
11041105
11051106static int do_create_stash (struct pathspec ps , struct strbuf * stash_msg_buf ,
11061107 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 )
11081110{
11091111 int ret = 0 ;
11101112 int flags = 0 ;
@@ -1124,7 +1126,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
11241126 refresh_cache (REFRESH_QUIET );
11251127
11261128 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" ));
11281132 ret = -1 ;
11291133 goto done ;
11301134 } else {
@@ -1149,34 +1153,39 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
11491153 if (write_cache_as_tree (& info -> i_tree , 0 , NULL ) ||
11501154 commit_tree (commit_tree_label .buf , commit_tree_label .len ,
11511155 & 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" ));
11531159 ret = -1 ;
11541160 goto done ;
11551161 }
11561162
11571163 if (include_untracked && get_untracked_files (ps , include_untracked ,
11581164 & untracked_files )) {
11591165 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" ));
11621169 ret = -1 ;
11631170 goto done ;
11641171 }
11651172 untracked_commit_option = 1 ;
11661173 }
11671174 if (patch_mode ) {
1168- ret = stash_patch (info , ps , patch );
1175+ ret = stash_patch (info , ps , patch , quiet );
11691176 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" ));
11721180 goto done ;
11731181 } else if (ret > 0 ) {
11741182 goto done ;
11751183 }
11761184 } else {
11771185 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" ));
11801189 ret = -1 ;
11811190 goto done ;
11821191 }
@@ -1202,7 +1211,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
12021211
12031212 if (commit_tree (stash_msg_buf -> buf , stash_msg_buf -> len , & info -> w_tree ,
12041213 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" ));
12061217 ret = -1 ;
12071218 goto done ;
12081219 }
@@ -1237,7 +1248,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
12371248 memset (& ps , 0 , sizeof (ps ));
12381249 strbuf_addstr (& stash_msg_buf , stash_msg );
12391250 ret = do_create_stash (ps , & stash_msg_buf , include_untracked , 0 , & info ,
1240- NULL );
1251+ NULL , 0 );
12411252
12421253 if (!ret )
12431254 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,
13001311
13011312 if (!reflog_exists (ref_stash ) && do_clear_stash ()) {
13021313 ret = -1 ;
1303- fprintf_ln (stderr , _ ("Cannot initialize stash" ));
1314+ if (!quiet )
1315+ fprintf_ln (stderr , _ ("Cannot initialize stash" ));
13041316 goto done ;
13051317 }
13061318
13071319 if (stash_msg )
13081320 strbuf_addstr (& stash_msg_buf , stash_msg );
13091321 if (do_create_stash (ps , & stash_msg_buf , include_untracked , patch_mode ,
1310- & info , & patch )) {
1322+ & info , & patch , quiet )) {
13111323 ret = -1 ;
13121324 goto done ;
13131325 }
13141326
13151327 if (do_store_stash (& info .w_commit , stash_msg_buf .buf , 1 )) {
13161328 ret = -1 ;
1317- fprintf_ln (stderr , _ ("Cannot save the current status" ));
1329+ if (!quiet )
1330+ fprintf_ln (stderr , _ ("Cannot save the current status" ));
13181331 goto done ;
13191332 }
13201333
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 );
13231337
13241338 if (!patch_mode ) {
13251339 if (include_untracked && !ps .nr ) {
@@ -1420,7 +1434,9 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
14201434 argv_array_pushl (& cp .args , "apply" , "-R" , NULL );
14211435
14221436 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" ));
14241440 ret = -1 ;
14251441 goto done ;
14261442 }
0 commit comments