@@ -301,14 +301,17 @@ static const char *skipspaces(const char *s)
301301
302302static int cmd_parseopt (int argc , const char * * argv , const char * prefix )
303303{
304- static int keep_dashdash = 0 ;
304+ static int keep_dashdash = 0 , stop_at_non_option = 0 ;
305305 static char const * const parseopt_usage [] = {
306306 "git rev-parse --parseopt [options] -- [<args>...]" ,
307307 NULL
308308 };
309309 static struct option parseopt_opts [] = {
310310 OPT_BOOLEAN (0 , "keep-dashdash" , & keep_dashdash ,
311311 "keep the `--` passed as an arg" ),
312+ OPT_BOOLEAN (0 , "stop-at-non-option" , & stop_at_non_option ,
313+ "stop parsing after the "
314+ "first non-option argument" ),
312315 OPT_END (),
313316 };
314317
@@ -394,7 +397,8 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
394397 ALLOC_GROW (opts , onb + 1 , osz );
395398 memset (opts + onb , 0 , sizeof (opts [onb ]));
396399 argc = parse_options (argc , argv , prefix , opts , usage ,
397- keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0 );
400+ keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0 |
401+ stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0 );
398402
399403 strbuf_addf (& parsed , " --" );
400404 sq_quote_argv (& parsed , argv , 0 );
0 commit comments