@@ -971,7 +971,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
971971}
972972
973973static int stash_patch (struct stash_info * info , struct pathspec ps ,
974- struct strbuf * out_patch )
974+ struct strbuf * out_patch , int quiet )
975975{
976976 int ret = 0 ;
977977 struct strbuf out = STRBUF_INIT ;
@@ -1024,7 +1024,8 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
10241024 }
10251025
10261026 if (!out_patch -> len ) {
1027- fprintf_ln (stderr , _ ("No changes selected" ));
1027+ if (!quiet )
1028+ fprintf_ln (stderr , _ ("No changes selected" ));
10281029 ret = 1 ;
10291030 }
10301031
@@ -1102,7 +1103,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
11021103
11031104static int do_create_stash (struct pathspec ps , struct strbuf * stash_msg_buf ,
11041105 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 )
11061108{
11071109 int ret = 0 ;
11081110 int flags = 0 ;
@@ -1120,7 +1122,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
11201122 refresh_cache (REFRESH_QUIET );
11211123
11221124 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" ));
11241128 ret = -1 ;
11251129 goto done ;
11261130 } else {
@@ -1145,34 +1149,39 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
11451149 if (write_cache_as_tree (& info -> i_tree , 0 , NULL ) ||
11461150 commit_tree (commit_tree_label .buf , commit_tree_label .len ,
11471151 & 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" ));
11491155 ret = -1 ;
11501156 goto done ;
11511157 }
11521158
11531159 if (include_untracked && get_untracked_files (ps , include_untracked ,
11541160 & untracked_files )) {
11551161 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" ));
11581165 ret = -1 ;
11591166 goto done ;
11601167 }
11611168 untracked_commit_option = 1 ;
11621169 }
11631170 if (patch_mode ) {
1164- ret = stash_patch (info , ps , patch );
1171+ ret = stash_patch (info , ps , patch , quiet );
11651172 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" ));
11681176 goto done ;
11691177 } else if (ret > 0 ) {
11701178 goto done ;
11711179 }
11721180 } else {
11731181 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" ));
11761185 ret = -1 ;
11771186 goto done ;
11781187 }
@@ -1204,7 +1213,9 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
12041213
12051214 if (commit_tree (stash_msg_buf -> buf , stash_msg_buf -> len , & info -> w_tree ,
12061215 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" ));
12081219 ret = -1 ;
12091220 goto done ;
12101221 }
@@ -1239,7 +1250,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
12391250 memset (& ps , 0 , sizeof (ps ));
12401251 strbuf_addstr (& stash_msg_buf , stash_msg );
12411252 ret = do_create_stash (ps , & stash_msg_buf , include_untracked , 0 , & info ,
1242- NULL );
1253+ NULL , 0 );
12431254
12441255 if (!ret )
12451256 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,
13021313
13031314 if (!reflog_exists (ref_stash ) && do_clear_stash ()) {
13041315 ret = -1 ;
1305- fprintf_ln (stderr , _ ("Cannot initialize stash" ));
1316+ if (!quiet )
1317+ fprintf_ln (stderr , _ ("Cannot initialize stash" ));
13061318 goto done ;
13071319 }
13081320
13091321 if (stash_msg )
13101322 strbuf_addstr (& stash_msg_buf , stash_msg );
13111323 if (do_create_stash (ps , & stash_msg_buf , include_untracked , patch_mode ,
1312- & info , & patch )) {
1324+ & info , & patch , quiet )) {
13131325 ret = -1 ;
13141326 goto done ;
13151327 }
13161328
13171329 if (do_store_stash (& info .w_commit , stash_msg_buf .buf , 1 )) {
13181330 ret = -1 ;
1319- fprintf_ln (stderr , _ ("Cannot save the current status" ));
1331+ if (!quiet )
1332+ fprintf_ln (stderr , _ ("Cannot save the current status" ));
13201333 goto done ;
13211334 }
13221335
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 );
13251339
13261340 if (!patch_mode ) {
13271341 if (include_untracked && !ps .nr ) {
@@ -1422,7 +1436,9 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
14221436 argv_array_pushl (& cp .args , "apply" , "-R" , NULL );
14231437
14241438 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" ));
14261442 ret = -1 ;
14271443 goto done ;
14281444 }
0 commit comments