-
Notifications
You must be signed in to change notification settings - Fork 411
/
Copy pathdelta.rs
802 lines (741 loc) · 27.1 KB
/
delta.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
use std::io::Write;
use ansi_term::Colour::{Blue, Yellow};
use console::strip_ansi_codes;
use unicode_segmentation::UnicodeSegmentation;
use crate::bat::assets::HighlightingAssets;
use crate::cli;
use crate::config::Config;
use crate::draw;
use crate::paint::Painter;
use crate::parse;
use crate::style;
#[derive(Debug, PartialEq)]
pub enum State {
CommitMeta, // In commit metadata section
FileMeta, // In diff metadata section, between (possible) commit metadata and first hunk
HunkMeta, // In hunk metadata line
HunkZero, // In hunk; unchanged line
HunkMinus, // In hunk; removed line
HunkPlus, // In hunk; added line
Unknown,
}
#[derive(Debug, PartialEq)]
pub enum Source {
GitDiff, // Coming from a `git diff` command
DiffUnified, // Coming from a `diff -u` command
Unknown,
}
impl State {
fn is_in_hunk(&self) -> bool {
match *self {
State::HunkMeta | State::HunkZero | State::HunkMinus | State::HunkPlus => true,
_ => false,
}
}
}
// Possible transitions, with actions on entry:
//
//
// | from \ to | CommitMeta | FileMeta | HunkMeta | HunkZero | HunkMinus | HunkPlus |
// |-------------+-------------+-------------+-------------+-------------+-------------+----------|
// | CommitMeta | emit | emit | | | | |
// | FileMeta | | emit | emit | | | |
// | HunkMeta | | | | emit | push | push |
// | HunkZero | emit | emit | emit | emit | push | push |
// | HunkMinus | flush, emit | flush, emit | flush, emit | flush, emit | push | push |
// | HunkPlus | flush, emit | flush, emit | flush, emit | flush, emit | flush, push | push |
pub fn delta<I>(
lines: I,
config: &Config,
assets: &HighlightingAssets,
writer: &mut dyn Write,
) -> std::io::Result<()>
where
I: Iterator<Item = String>,
{
let mut lines_peekable = lines.peekable();
let mut painter = Painter::new(writer, config, assets);
let mut minus_file = "".to_string();
let mut plus_file;
let mut state = State::Unknown;
let source = detect_source(&mut lines_peekable);
for raw_line in lines_peekable {
if source == Source::Unknown {
writeln!(painter.writer, "{}", raw_line)?;
continue;
}
let line = strip_ansi_codes(&raw_line).to_string();
if line.starts_with("commit ") {
painter.paint_buffered_lines();
state = State::CommitMeta;
if config.opt.commit_style != cli::SectionStyle::Plain {
painter.emit()?;
handle_commit_meta_header_line(&mut painter, &raw_line, config)?;
continue;
}
} else if line.starts_with("diff ") {
painter.paint_buffered_lines();
state = State::FileMeta;
painter.set_syntax(parse::get_file_extension_from_diff_line(&line));
} else if (line.starts_with("--- ") || line.starts_with("rename from "))
&& config.opt.file_style != cli::SectionStyle::Plain
{
if source == Source::DiffUnified {
state = State::FileMeta;
painter.set_syntax(parse::get_file_extension_from_marker_line(&line));
}
minus_file = parse::get_file_path_from_file_meta_line(&line, source == Source::GitDiff);
} else if (line.starts_with("+++ ") || line.starts_with("rename to "))
&& config.opt.file_style != cli::SectionStyle::Plain
{
plus_file = parse::get_file_path_from_file_meta_line(&line, source == Source::GitDiff);
painter.emit()?;
handle_file_meta_header_line(
&mut painter,
&minus_file,
&plus_file,
config,
source == Source::DiffUnified,
)?;
} else if line.starts_with("@@ ") {
state = State::HunkMeta;
painter.set_highlighter();
if config.opt.hunk_style != cli::SectionStyle::Plain {
painter.emit()?;
handle_hunk_meta_line(&mut painter, &line, config)?;
continue;
}
} else if source == Source::DiffUnified && line.starts_with("Only in ")
|| line.starts_with("Submodule ")
{
// Additional FileMeta cases:
//
// 1. When comparing directories with diff -u, if filenames match between the
// directories, the files themselves will be compared. However, if an equivalent
// filename is not present, diff outputs a single line (Only in...) starting
// indicating that the file is present in only one of the directories.
//
// 2. Git diff emits lines describing submodule state such as "Submodule x/y/z contains
// untracked content"
//
// See https://github.com/dandavison/delta/issues/60#issuecomment-557485242 for a
// proposal for more robust parsing logic.
state = State::FileMeta;
painter.paint_buffered_lines();
if config.opt.file_style != cli::SectionStyle::Plain {
painter.emit()?;
handle_generic_file_meta_header_line(&mut painter, &raw_line, config)?;
continue;
}
} else if state.is_in_hunk() {
state = handle_hunk_line(&mut painter, &line, state, config);
painter.emit()?;
continue;
}
if state == State::FileMeta && config.opt.file_style != cli::SectionStyle::Plain {
// The file metadata section is 4 lines. Skip them under non-plain file-styles.
continue;
} else {
painter.emit()?;
writeln!(painter.writer, "{}", raw_line)?;
}
}
painter.paint_buffered_lines();
painter.emit()?;
Ok(())
}
/// Try to detect what is producing the input for delta by examining the first line
///
/// Currently can detect:
/// * git diff
/// * diff -u
///
/// If the source is not recognized, delta will print the unaltered
/// input back out
fn detect_source<I>(lines: &mut std::iter::Peekable<I>) -> Source
where
I: Iterator<Item = String>,
{
lines.peek().map_or(Source::Unknown, |first_line| {
let line = strip_ansi_codes(&first_line).to_string();
if line.starts_with("commit ") || line.starts_with("diff --git ") {
Source::GitDiff
} else if line.starts_with("diff -u ")
|| line.starts_with("diff -U")
|| line.starts_with("--- ")
{
Source::DiffUnified
} else {
Source::Unknown
}
})
}
fn handle_commit_meta_header_line(
painter: &mut Painter,
line: &str,
config: &Config,
) -> std::io::Result<()> {
let draw_fn = match config.opt.commit_style {
cli::SectionStyle::Box => draw::write_boxed_with_line,
cli::SectionStyle::Underline => draw::write_underlined,
cli::SectionStyle::Plain => panic!(),
};
draw_fn(
painter.writer,
line,
config.terminal_width,
Yellow.normal(),
true,
)?;
Ok(())
}
/// Construct file change line from minus and plus file and write with FileMeta styling.
fn handle_file_meta_header_line(
painter: &mut Painter,
minus_file: &str,
plus_file: &str,
config: &Config,
comparing: bool,
) -> std::io::Result<()> {
let line = parse::get_file_change_description_from_file_paths(minus_file, plus_file, comparing);
handle_generic_file_meta_header_line(painter, &line, config)
}
/// Write `line` with FileMeta styling.
fn handle_generic_file_meta_header_line(
painter: &mut Painter,
line: &str,
config: &Config,
) -> std::io::Result<()> {
let draw_fn = match config.opt.file_style {
cli::SectionStyle::Box => draw::write_boxed_with_line,
cli::SectionStyle::Underline => draw::write_underlined,
cli::SectionStyle::Plain => panic!(),
};
let ansi_style = Blue.normal();
writeln!(painter.writer)?;
draw_fn(
painter.writer,
&ansi_style.paint(line),
config.terminal_width,
ansi_style,
false,
)?;
Ok(())
}
fn handle_hunk_meta_line(
painter: &mut Painter,
line: &str,
config: &Config,
) -> std::io::Result<()> {
let draw_fn = match config.opt.hunk_style {
cli::SectionStyle::Box => draw::write_boxed,
cli::SectionStyle::Underline => draw::write_underlined,
cli::SectionStyle::Plain => panic!(),
};
let ansi_style = Blue.normal();
let (raw_code_fragment, line_number) = parse::parse_hunk_metadata(&line);
let code_fragment = prepare(raw_code_fragment, config.tab_width, false);
if !code_fragment.is_empty() {
let syntax_style_sections = Painter::get_line_syntax_style_sections(
&code_fragment,
&mut painter.highlighter,
&painter.config,
true,
);
Painter::paint_lines(
&mut painter.output_buffer,
vec![syntax_style_sections],
vec![vec![(
style::NO_BACKGROUND_COLOR_STYLE_MODIFIER,
&code_fragment,
)]],
config,
style::NO_BACKGROUND_COLOR_STYLE_MODIFIER,
false,
);
painter.output_buffer.pop(); // trim newline
draw_fn(
painter.writer,
&painter.output_buffer,
config.terminal_width,
ansi_style,
false,
)?;
painter.output_buffer.clear();
}
writeln!(painter.writer, "\n{}", ansi_style.paint(line_number))?;
Ok(())
}
/// Handle a hunk line, i.e. a minus line, a plus line, or an unchanged line.
// In the case of a minus or plus line, we store the line in a
// buffer. When we exit the changed region we process the collected
// minus and plus lines jointly, in order to paint detailed
// highlighting according to inferred edit operations. In the case of
// an unchanged line, we paint it immediately.
fn handle_hunk_line(painter: &mut Painter, line: &str, state: State, config: &Config) -> State {
// Don't let the line buffers become arbitrarily large -- if we
// were to allow that, then for a large deleted/added file we
// would process the entire file before painting anything.
if painter.minus_lines.len() > config.max_buffered_lines
|| painter.plus_lines.len() > config.max_buffered_lines
{
painter.paint_buffered_lines();
}
match line.chars().next() {
Some('-') => {
if state == State::HunkPlus {
painter.paint_buffered_lines();
}
painter
.minus_lines
.push(prepare(&line, config.tab_width, true));
State::HunkMinus
}
Some('+') => {
painter
.plus_lines
.push(prepare(&line, config.tab_width, true));
State::HunkPlus
}
_ => {
painter.paint_buffered_lines();
let line = prepare(&line, config.tab_width, true);
let syntax_style_sections = Painter::get_line_syntax_style_sections(
&line,
&mut painter.highlighter,
&painter.config,
true,
);
Painter::paint_lines(
&mut painter.output_buffer,
vec![syntax_style_sections],
vec![vec![(style::NO_BACKGROUND_COLOR_STYLE_MODIFIER, &line)]],
config,
style::NO_BACKGROUND_COLOR_STYLE_MODIFIER,
true,
);
State::HunkZero
}
}
}
/// Replace initial -/+ character with ' ', expand tabs as spaces, and optionally terminate with
/// newline.
// Terminating with newline character is necessary for many of the sublime syntax definitions to
// highlight correctly.
// See https://docs.rs/syntect/3.2.0/syntect/parsing/struct.SyntaxSetBuilder.html#method.add_from_folder
fn prepare(line: &str, tab_width: usize, append_newline: bool) -> String {
let terminator = if append_newline { "\n" } else { "" };
if !line.is_empty() {
let mut line = line.graphemes(true);
// The first column contains a -/+/space character, added by git. We skip it here and insert
// a replacement space when formatting the line below.
line.next();
// Expand tabs as spaces.
// tab_width = 0 is documented to mean do not replace tabs.
let output_line = if tab_width > 0 {
let tab_replacement = " ".repeat(tab_width);
line.map(|s| if s == "\t" { &tab_replacement } else { s })
.collect::<String>()
} else {
line.collect::<String>()
};
format!(" {}{}", output_line, terminator)
} else {
terminator.to_string()
}
}
#[cfg(test)]
mod tests {
use super::*;
use console::strip_ansi_codes;
use std::env;
use syntect::highlighting::StyleModifier;
use crate::paint;
#[test]
fn test_added_file() {
let options = get_command_line_options();
let output = strip_ansi_codes(&run_delta(ADDED_FILE_INPUT, &options)).to_string();
assert!(output.contains("\nadded: a.py\n"));
if false {
// TODO: hline width
assert_eq!(output, ADDED_FILE_EXPECTED_OUTPUT);
}
}
#[test]
fn test_renamed_file() {
let options = get_command_line_options();
let output = strip_ansi_codes(&run_delta(RENAMED_FILE_INPUT, &options)).to_string();
assert!(output.contains("\nrenamed: a.py ⟶ b.py\n"));
}
#[test]
fn test_recognized_file_type() {
// In addition to the background color, the code has language syntax highlighting.
let options = get_command_line_options();
let input = ADDED_FILE_INPUT;
let output = get_line_of_code_from_delta(&input, &options);
assert_has_color_other_than_plus_color(&output, &options);
}
#[test]
fn test_unrecognized_file_type_with_theme() {
// In addition to the background color, the code has the foreground color using the default
// .txt syntax under the theme.
let options = get_command_line_options();
let input = ADDED_FILE_INPUT.replace("a.py", "a");
let output = get_line_of_code_from_delta(&input, &options);
assert_has_color_other_than_plus_color(&output, &options);
}
#[test]
fn test_unrecognized_file_type_no_theme() {
// The code has the background color only. (Since there is no theme, the code has no
// foreground ansi color codes.)
let mut options = get_command_line_options();
options.theme = Some("none".to_string());
let input = ADDED_FILE_INPUT.replace("a.py", "a");
let output = get_line_of_code_from_delta(&input, &options);
assert_has_plus_color_only(&output, &options);
}
#[test]
fn test_theme_selection() {
enum Mode {
Light,
Dark,
};
let assets = HighlightingAssets::new();
for (
theme_option,
bat_theme_env_var,
mode_option, // (--light, --dark)
expected_theme,
expected_mode,
) in vec![
(None, "", None, style::DEFAULT_DARK_THEME, Mode::Dark),
(Some("GitHub".to_string()), "", None, "GitHub", Mode::Light),
(
Some("GitHub".to_string()),
"1337",
None,
"GitHub",
Mode::Light,
),
(None, "1337", None, "1337", Mode::Dark),
(
None,
"<not set>",
None,
style::DEFAULT_DARK_THEME,
Mode::Dark,
),
(
None,
"",
Some(Mode::Light),
style::DEFAULT_LIGHT_THEME,
Mode::Light,
),
(
None,
"",
Some(Mode::Dark),
style::DEFAULT_DARK_THEME,
Mode::Dark,
),
(
None,
"<@@@@@>",
Some(Mode::Light),
style::DEFAULT_LIGHT_THEME,
Mode::Light,
),
(None, "1337", Some(Mode::Light), "1337", Mode::Light),
(Some("none".to_string()), "", None, "none", Mode::Dark),
(
Some("None".to_string()),
"",
Some(Mode::Light),
"None",
Mode::Light,
),
] {
if bat_theme_env_var == "<not set>" {
env::remove_var("BAT_THEME")
} else {
env::set_var("BAT_THEME", bat_theme_env_var);
}
let mut options = get_command_line_options();
options.theme = theme_option;
match mode_option {
Some(Mode::Light) => {
options.light = true;
options.dark = false;
}
Some(Mode::Dark) => {
options.light = false;
options.dark = true;
}
None => {
options.light = false;
options.dark = false;
}
}
let config = cli::process_command_line_arguments(&assets, &options);
assert_eq!(config.theme_name, expected_theme);
if style::is_no_syntax_highlighting_theme_name(expected_theme) {
assert!(config.theme.is_none())
} else {
assert_eq!(config.theme.unwrap().name.as_ref().unwrap(), expected_theme);
}
assert_eq!(
config.minus_style_modifier.background.unwrap(),
match expected_mode {
Mode::Light => style::LIGHT_THEME_MINUS_COLOR,
Mode::Dark => style::DARK_THEME_MINUS_COLOR,
}
);
assert_eq!(
config.minus_emph_style_modifier.background.unwrap(),
match expected_mode {
Mode::Light => style::LIGHT_THEME_MINUS_EMPH_COLOR,
Mode::Dark => style::DARK_THEME_MINUS_EMPH_COLOR,
}
);
assert_eq!(
config.plus_style_modifier.background.unwrap(),
match expected_mode {
Mode::Light => style::LIGHT_THEME_PLUS_COLOR,
Mode::Dark => style::DARK_THEME_PLUS_COLOR,
}
);
assert_eq!(
config.plus_emph_style_modifier.background.unwrap(),
match expected_mode {
Mode::Light => style::LIGHT_THEME_PLUS_EMPH_COLOR,
Mode::Dark => style::DARK_THEME_PLUS_EMPH_COLOR,
}
);
}
}
fn assert_has_color_other_than_plus_color(string: &str, options: &cli::Opt) {
let (string_without_any_color, string_with_plus_color_only) =
get_color_variants(string, &options);
assert_ne!(string, string_without_any_color);
assert_ne!(string, string_with_plus_color_only);
}
fn assert_has_plus_color_only(string: &str, options: &cli::Opt) {
let (string_without_any_color, string_with_plus_color_only) =
get_color_variants(string, &options);
assert_ne!(string, string_without_any_color);
assert_eq!(string, string_with_plus_color_only);
}
fn get_color_variants(string: &str, options: &cli::Opt) -> (String, String) {
let assets = HighlightingAssets::new();
let config = cli::process_command_line_arguments(&assets, &options);
let string_without_any_color = strip_ansi_codes(string).to_string();
let string_with_plus_color_only = paint_text(
&string_without_any_color,
config.plus_style_modifier,
&config,
);
(string_without_any_color, string_with_plus_color_only)
}
fn paint_text(input: &str, style_modifier: StyleModifier, config: &Config) -> String {
let mut output = String::new();
let style = config.no_style.apply(style_modifier);
paint::paint_text(&input, style, &mut output);
output
}
fn get_line_of_code_from_delta(input: &str, options: &cli::Opt) -> String {
let output = run_delta(&input, &options);
let line_of_code = output.lines().nth(12).unwrap();
assert!(strip_ansi_codes(line_of_code) == " class X:");
line_of_code.to_string()
}
fn run_delta(input: &str, options: &cli::Opt) -> String {
let mut writer: Vec<u8> = Vec::new();
let assets = HighlightingAssets::new();
let config = cli::process_command_line_arguments(&assets, &options);
delta(
input.split("\n").map(String::from),
&config,
&assets,
&mut writer,
)
.unwrap();
String::from_utf8(writer).unwrap()
}
fn get_command_line_options() -> cli::Opt {
cli::Opt {
light: false,
dark: false,
minus_color: None,
minus_emph_color: None,
plus_color: None,
plus_emph_color: None,
theme: None,
highlight_removed: false,
commit_style: cli::SectionStyle::Plain,
file_style: cli::SectionStyle::Underline,
hunk_style: cli::SectionStyle::Box,
width: Some("variable".to_string()),
tab_width: 4,
show_background_colors: false,
list_languages: false,
list_theme_names: false,
list_themes: false,
max_line_distance: 0.3,
}
}
#[test]
fn test_diff_unified_two_files() {
let options = get_command_line_options();
let output = strip_ansi_codes(&run_delta(DIFF_UNIFIED_TWO_FILES, &options)).to_string();
let mut lines = output.split('\n');
// Header
assert_eq!(lines.nth(1).unwrap(), "comparing: one.rs ⟶ src/two.rs");
// Line
assert_eq!(lines.nth(2).unwrap(), "5");
// Change
assert_eq!(lines.nth(2).unwrap(), " println!(\"Hello ruster\");");
// Next chunk
assert_eq!(lines.nth(2).unwrap(), "43");
// Unchanged in second chunk
assert_eq!(lines.nth(2).unwrap(), " Unchanged");
}
#[test]
fn test_diff_unified_two_directories() {
let options = get_command_line_options();
let output =
strip_ansi_codes(&run_delta(DIFF_UNIFIED_TWO_DIRECTORIES, &options)).to_string();
let mut lines = output.split('\n');
// Header
assert_eq!(
lines.nth(1).unwrap(),
"comparing: a/different ⟶ b/different"
);
// Line number
assert_eq!(lines.nth(2).unwrap(), "1");
// Change
assert_eq!(lines.nth(2).unwrap(), " This is different from b");
// File uniqueness
assert_eq!(lines.nth(2).unwrap(), "Only in a/: just_a");
// FileMeta divider
assert!(lines.next().unwrap().starts_with("───────"));
// Next hunk
assert_eq!(
lines.nth(4).unwrap(),
"comparing: a/more_difference ⟶ b/more_difference"
);
}
#[test]
fn test_delta_ignores_non_diff_input() {
let options = get_command_line_options();
let output = strip_ansi_codes(&run_delta(NOT_A_DIFF_OUTPUT, &options)).to_string();
assert_eq!(output, NOT_A_DIFF_OUTPUT.to_owned() + "\n");
}
#[test]
fn test_submodule_contains_untracked_content() {
let options = get_command_line_options();
let output = strip_ansi_codes(&run_delta(
SUBMODULE_CONTAINS_UNTRACKED_CONTENT_INPUT,
&options,
))
.to_string();
assert!(output.contains("\nSubmodule x/y/z contains untracked content\n"));
}
const ADDED_FILE_INPUT: &str = "\
commit d28dc1ac57e53432567ec5bf19ad49ff90f0f7a5
Author: Dan Davison <[email protected]>
Date: Thu Jul 11 10:41:11 2019 -0400
.
diff --git a/a.py b/a.py
new file mode 100644
index 0000000..8c55b7d
--- /dev/null
+++ b/a.py
@@ -0,0 +1,3 @@
+# hello
+class X:
+ pass";
const ADDED_FILE_EXPECTED_OUTPUT: &str = "\
commit d28dc1ac57e53432567ec5bf19ad49ff90f0f7a5
Author: Dan Davison <[email protected]>
Date: Thu Jul 11 10:41:11 2019 -0400
.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
added: a.py
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
────────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────
# hello
class X:
pass
";
const RENAMED_FILE_INPUT: &str = "\
commit 1281650789680f1009dfff2497d5ccfbe7b96526
Author: Dan Davison <[email protected]>
Date: Wed Jul 17 20:40:23 2019 -0400
rename
diff --git a/a.py b/b.py
similarity index 100%
rename from a.py
rename to b.py
";
const DIFF_UNIFIED_TWO_FILES: &str = "\
--- one.rs 2019-11-20 06:16:08.000000000 +0100
+++ src/two.rs 2019-11-18 18:41:16.000000000 +0100
@@ -5,3 +5,3 @@
println!(\"Hello world\");
-println!(\"Hello rust\");
+println!(\"Hello ruster\");
@@ -43,6 +43,6 @@
// Some more changes
-Change one
Unchanged
+Change two
Unchanged
-Change three
+Change four
Unchanged
";
const DIFF_UNIFIED_TWO_DIRECTORIES: &str = "\
diff -u a/different b/different
--- a/different 2019-11-20 06:47:56.000000000 +0100
+++ b/different 2019-11-20 06:47:56.000000000 +0100
@@ -1,3 +1,3 @@
A simple file for testing
the diff command in unified mode
-This is different from b
+This is different from a
Only in a/: just_a
Only in b/: just_b
--- a/more_difference 2019-11-20 06:47:56.000000000 +0100
+++ b/more_difference 2019-11-20 06:47:56.000000000 +0100
@@ -1,3 +1,3 @@
Another different file
with a name that start with 'm' making it come after the 'Only in'
-This is different from b
+This is different from a
";
const NOT_A_DIFF_OUTPUT: &str = "\
Hello world
This is a regular file that contains:
--- some/file/here 06:47:56.000000000 +0100
+++ some/file/there 06:47:56.000000000 +0100
Some text here
-Some text with a minus
+Some text with a plus
";
const SUBMODULE_CONTAINS_UNTRACKED_CONTENT_INPUT: &str = "\
--- a
+++ b
@@ -2,3 +2,4 @@
x
y
z
-a
+b
z
y
x
Submodule x/y/z contains untracked content
";
}