Repository: dandavison/delta
Pull request #563 (2021-04-19 20:09:21)

Support matching GitHub remotes that don't end in `.git`
`.git` is optional in clones from GitHub.com.


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index b9f3707..96844e1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -284,9 +284,9 @@ dependencies = [
 
 [[package]]
 name = "git2"
-version = "0.13.17"
+version = "0.13.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1d250f5f82326884bd39c2853577e70a121775db76818ffa452ed1e80de12986"
+checksum = "b483c6c2145421099df1b4efd50e0f6205479a072199460eff852fa15e5603c7"
 dependencies = [
  "bitflags",
  "libc",
@@ -387,9 +387,9 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
 
 [[package]]
 name = "libgit2-sys"
-version = "0.12.18+1.1.0"
+version = "0.12.19+1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3da6a42da88fc37ee1ecda212ffa254c25713532980005d5f7c0b0fbe7e6e885"
+checksum = "f322155d574c8b9ebe991a04f6908bb49e68a79463338d24a43d6274cb6443e6"
 dependencies = [
  "cc",
  "libc",
@@ -582,9 +582,9 @@ dependencies = [
 
 [[package]]
 name = "regex"
-version = "1.4.5"
+version = "1.4.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
+checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759"
 dependencies = [
  "aho-corasick",
  "memchr",
diff --git a/Cargo.toml b/Cargo.toml
index d6043ae..b4e003e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,7 +25,7 @@ console = "0.14.1"
 dirs-next = "2.0.0"
 itertools = "0.10.0"
 lazy_static = "1.4"
-regex = "1.4.5"
+regex = "1.4.6"
 shell-words = "1.0.0"
 structopt = "0.3.21"
 unicode-segmentation = "1.7.1"
@@ -34,7 +34,7 @@ vte = "0.10.0"
 xdg = "2.2.0"
 
 [dependencies.git2]
-version = "0.13.17"
+version = "0.13.18"
 default-features = false
 features = []
 
diff --git a/Makefile b/Makefile
index 7b439c2..5396ff2 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ build:
 	cargo build --release
 
 format:
-	git ls-files | grep '\.rs$' | xargs -P 0 rustfmt
+	git ls-files | grep '\.rs$$' | xargs -P 0 rustfmt
 
 lint:
 	cargo clippy
diff --git a/src/cli.rs b/src/cli.rs
index 2ee7324..ca46545 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -494,9 +494,13 @@ pub struct Opt {
     /// has the value "truecolor" or "24bit". If your terminal application (the application you use
     /// to enter commands at a shell prompt) supports 24 bit colors, then it probably already sets
     /// this environment variable, in which case you don't need to do anything.
-    #[structopt(long = "24-bit-color", default_value = "auto")]
+    #[structopt(long = "true-color", default_value = "auto")]
     pub true_color: String,
 
+    /// Deprecated: use --true-color.
+    #[structopt(long = "24-bit-color")]
+    pub _24_bit_color: Option<String>,
+
     /// Whether to examine ANSI color escape sequences in raw lines received from Git and handle
     /// lines colored in certain ways specially. This is on by default: it is how Delta supports
     /// Git's --color-moved feature. Set this to "false" to disable this behavior.
diff --git a/src/git_config/git_config_entry.rs b/src/git_config/git_config_entry.rs
index 2764e2b..4b0d80a 100644
--- a/src/git_config/git_config_entry.rs
+++ b/src/git_config/git_config_entry.rs
@@ -20,7 +20,7 @@ pub enum GitRemoteRepo {
 }
 
 lazy_static! {
-    static ref GITHUB_REMOTE_URL: Regex = Regex::new(r"github\.com[:/]([^/]+)/(.+)\.git").unwrap();
+    static ref GITHUB_REMOTE_URL: Regex = Regex::new(r"github\.com[:/]([^/]+)/(.+)").unwrap();
 }
 
 impl FromStr for GitRemoteRepo {
diff --git a/src/main.rs b/src/main.rs
index c99fb46..c687346 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -197,7 +197,7 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu
     // Everything else
     writeln!(
         writer,
-        "    24-bit-color                  = {true_color}
+        "    true-color                    = {true_color}
     file-added-label              = {file_added_label}
     file-modified-label           = {file_modified_label}
     file-removed-label            = {file_removed_label}
@@ -375,13 +375,25 @@ fn show_syntax_themes() -> std::io::Result<()> {
     let mut writer = output_type.handle().unwrap();
     opt.computed.syntax_set = assets.syntax_set;
 
+    let stdin_data = if !atty::is(atty::Stream::Stdin) {
+        let mut buf = Vec::new();
+        io::stdin().lock().read_to_end(&mut buf)?;
+        if !buf.is_empty() {
+            Some(buf)
+        } else {
+            None
+        }
+    } else {
+        None
+    };
+
     if !(opt.dark || opt.light) {
-        _show_syntax_themes(opt.clone(), false, &mut writer)?;
-        _show_syntax_themes(opt, true, &mut writer)?;
+        _show_syntax_themes(opt.clone(), false, &mut writer, stdin_data.as_ref())?;
+        _show_syntax_themes(opt, true, &mut writer, stdin_data.as_ref())?;
     } else if opt.light {
-        _show_syntax_themes(opt, true, &mut writer)?;
+        _show_syntax_themes(opt, true, &mut writer, stdin_data.as_ref())?;
     } else {
-        _show_syntax_themes(opt, false, &mut writer)?
+        _show_syntax_themes(opt, false, &mut writer, stdin_data.as_ref())?
     };
     Ok(())
 }
@@ -390,10 +402,14 @@ fn _show_syntax_themes(
     mut opt: cli::Opt,
     is_light_mode: bool,
     writer: &mut dyn Write,
+    stdin: Option<&Vec<u8>>,
 ) -> std::io::Result<()> {
     use bytelines::ByteLines;
     use std::io::BufReader;
-    let mut input = b"\
+    let input = match stdin {
+        Some(stdin_data) => &stdin_data[..],
+        None => {
+            b"\
 diff --git a/example.rs b/example.rs
 index f38589a..0f1bb83 100644
 --- a/example.rs
@@ -408,12 +424,6 @@ index f38589a..0f1bb83 100644
 +    let result = f64::powf(num, 3.0);
 +    println!(\"The cube of {:.2} is {:.2}.\", num, result);
 "
-    .to_vec();
-    if !atty::is(atty::Stream::Stdin) {
-        let mut buf = Vec::new();
-        io::stdin().lock().read_to_end(&mut buf)?;
-        if !buf.is_empty() {
-            input = buf;
         }
     };
 
@@ -520,12 +530,12 @@ mod main_tests {
         let opt = integration_test_utils::make_options_from_args(&[]);
 
         let mut writer = Cursor::new(vec![0; 1024]);
-        _show_syntax_themes(opt, true, &mut writer).unwrap();
+        _show_syntax_themes(opt, true, &mut writer, None).unwrap();
         let mut s = String::new();
         writer.seek(SeekFrom::Start(0)).unwrap();
         writer.read_to_string(&mut s).unwrap();
         let s = ansi::strip_ansi_codes(&s);
-        assert!(s.contains("\nTheme: gruvbox-white\n"));
+        assert!(s.contains("\nTheme: gruvbox-light\n"));
         println!("{}", s);
         assert!(s.contains("\nfn print_cube(num: f64) {\n"));
     }
diff --git a/src/options/set.rs b/src/options/set.rs
index c04bcb8..2d112f8 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -40,6 +40,7 @@ macro_rules! set_options {
         )*
         if $check_names {
             option_names.extend(&[
+                "24-bit-color",
                 "diff-highlight", // Does not exist as a flag on config
                 "diff-so-fancy", // Does not exist as a flag on config
                 "features",  // Processed differently
@@ -551,13 +552,20 @@ fn set_widths(
 }
 
 fn set_true_color(opt: &mut cli::Opt) {
+    if opt.true_color == "auto" {
+        // It's equal to its default, so the user might be using the deprecated
+        // --24-bit-color option.
+        if let Some(_24_bit_color) = opt._24_bit_color.as_ref() {
+            opt.true_color = _24_bit_color.clone();
+        }
+    }
     opt.computed.true_color = match opt.true_color.as_ref() {
         "always" => true,
         "never" => false,
         "auto" => is_truecolor_terminal(),
         _ => {
             eprintln!(
-                "Invalid value for --24-bit-color option: {} (valid values are \"always\", \"never\", and \"auto\")",
+                "Invalid value for --true-color option: {} (valid values are \"always\", \"never\", and \"auto\")",
                 opt.true_color
             );
             process::exit(1);
@@ -614,7 +622,6 @@ pub mod tests {
         // since e.g. color-only = true (non-default) forces side-by-side = false (default).
         let git_config_contents = b"
 [delta]
-    24-bit-color = never
     color-only = false
     commit-decoration-style = black black
     commit-style = black black
@@ -656,6 +663,7 @@ pub mod tests {
     side-by-side = true
     syntax-theme = xxxyyyzzz
     tabs = 77
+    true-color = never
     whitespace-error-style = black black
     width = 77
     word-diff-regex = xxxyyyzzz
diff --git a/src/options/theme.rs b/src/options/theme.rs
index eb1fd50..ef46dbe 100644
--- a/src/options/theme.rs
+++ b/src/options/theme.rs
@@ -188,10 +188,10 @@ mod tests {
             }
             let is_true_color = true;
             if is_true_color {
-                args.push("--24-bit-color");
+                args.push("--true-color");
                 args.push("always");
             } else {
-                args.push("--24-bit-color");
+                args.push("--true-color");
                 args.push("never");
             }
             match mode {


Test patch:
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 51c713f..de35535 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -928,7 +928,7 @@ src/align.rs
             &["--color-only", "--max-line-length", "1"],
             &["--color-only", "--width", "1"],
             &["--color-only", "--tabs", "10"],
-            &["--color-only", "--24-bit-color", "always"],
+            &["--color-only", "--true-color", "always"],
             &["--color-only", "--inspect-raw-lines", "false"],
             &["--color-only", "--whitespace-error-style", "22 reverse"],
         ];