9
9
#include "diff.h"
10
10
#include "hashmap.h"
11
11
#include "argv-array.h"
12
+ #include "run-command.h"
12
13
13
14
#define SEEN (1u << 0)
14
15
#define MAX_TAGS (FLAG_BITS - 1)
@@ -31,7 +32,7 @@ static int have_util;
31
32
static struct string_list patterns = STRING_LIST_INIT_NODUP ;
32
33
static struct string_list exclude_patterns = STRING_LIST_INIT_NODUP ;
33
34
static int always ;
34
- static const char * dirty ;
35
+ static const char * suffix , * dirty , * broken ;
35
36
36
37
/* diff-index command arguments to check if working tree is dirty. */
37
38
static const char * diff_index_args [] = {
@@ -292,8 +293,8 @@ static void describe(const char *arg, int last_one)
292
293
display_name (n );
293
294
if (longformat )
294
295
show_suffix (0 , n -> tag ? & n -> tag -> tagged -> oid : & oid );
295
- if (dirty )
296
- printf ("%s" , dirty );
296
+ if (suffix )
297
+ printf ("%s" , suffix );
297
298
printf ("\n" );
298
299
return ;
299
300
}
@@ -369,8 +370,8 @@ static void describe(const char *arg, int last_one)
369
370
struct object_id * oid = & cmit -> object .oid ;
370
371
if (always ) {
371
372
printf ("%s" , find_unique_abbrev (oid -> hash , abbrev ));
372
- if (dirty )
373
- printf ("%s" , dirty );
373
+ if (suffix )
374
+ printf ("%s" , suffix );
374
375
printf ("\n" );
375
376
return ;
376
377
}
@@ -413,8 +414,8 @@ static void describe(const char *arg, int last_one)
413
414
display_name (all_matches [0 ].name );
414
415
if (abbrev )
415
416
show_suffix (all_matches [0 ].depth , & cmit -> object .oid );
416
- if (dirty )
417
- printf ("%s" , dirty );
417
+ if (suffix )
418
+ printf ("%s" , suffix );
418
419
printf ("\n" );
419
420
420
421
if (!last_one )
@@ -445,6 +446,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
445
446
{OPTION_STRING , 0 , "dirty" , & dirty , N_ ("mark" ),
446
447
N_ ("append <mark> on dirty working tree (default: \"-dirty\")" ),
447
448
PARSE_OPT_OPTARG , NULL , (intptr_t ) "-dirty" },
449
+ {OPTION_STRING , 0 , "broken" , & broken , N_ ("mark" ),
450
+ N_ ("append <mark> on broken working tree (default: \"-broken\")" ),
451
+ PARSE_OPT_OPTARG , NULL , (intptr_t ) "-broken" },
448
452
OPT_END (),
449
453
};
450
454
@@ -493,7 +497,28 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
493
497
die (_ ("No names found, cannot describe anything." ));
494
498
495
499
if (argc == 0 ) {
496
- if (dirty ) {
500
+ if (broken ) {
501
+ struct child_process cp = CHILD_PROCESS_INIT ;
502
+ argv_array_pushv (& cp .args , diff_index_args );
503
+ cp .git_cmd = 1 ;
504
+ cp .no_stdin = 1 ;
505
+ cp .no_stdout = 1 ;
506
+
507
+ if (!dirty )
508
+ dirty = "-dirty" ;
509
+
510
+ switch (run_command (& cp )) {
511
+ case 0 :
512
+ suffix = NULL ;
513
+ break ;
514
+ case 1 :
515
+ suffix = dirty ;
516
+ break ;
517
+ default :
518
+ /* diff-index aborted abnormally */
519
+ suffix = broken ;
520
+ }
521
+ } else if (dirty ) {
497
522
static struct lock_file index_lock ;
498
523
int fd ;
499
524
@@ -506,11 +531,15 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
506
531
507
532
if (!cmd_diff_index (ARRAY_SIZE (diff_index_args ) - 1 ,
508
533
diff_index_args , prefix ))
509
- dirty = NULL ;
534
+ suffix = NULL ;
535
+ else
536
+ suffix = dirty ;
510
537
}
511
538
describe ("HEAD" , 1 );
512
539
} else if (dirty ) {
513
540
die (_ ("--dirty is incompatible with commit-ishes" ));
541
+ } else if (broken ) {
542
+ die (_ ("--broken is incompatible with commit-ishes" ));
514
543
} else {
515
544
while (argc -- > 0 )
516
545
describe (* argv ++ , argc == 0 );
0 commit comments