소스 검색

fix(git-repo): Don’t truncate branch name

ariasuni 2 년 전
부모
커밋
2b879d0728
3개의 변경된 파일6개의 추가작업 그리고 18개의 파일을 삭제
  1. 1 10
      src/fs/feature/git.rs
  2. 4 7
      src/output/render/git.rs
  3. 1 1
      src/output/table.rs

+ 1 - 10
src/fs/feature/git.rs

@@ -396,16 +396,7 @@ fn current_branch(repo: &git2::Repository) -> Option<String> {
         }
     };
 
-    if let Some(h) = head {
-        if let Some(s) = h.shorthand() {
-            let branch_name = s.to_owned();
-            if branch_name.len() > 10 {
-                return Some(branch_name[..8].to_string() + "..");
-            }
-            return Some(branch_name);
-        }
-    }
-    None
+    head.and_then(|h| h.shorthand().map(std::string::ToString::to_string))
 }
 
 impl f::SubdirGitRepo {

+ 4 - 7
src/output/render/git.rs

@@ -51,13 +51,10 @@ pub trait Colours {
 impl f::SubdirGitRepo {
     pub fn render(self, colours: &dyn RepoColours) -> TextCell {
         let branch_name = match self.branch {
-            Some(name) => {
-                if name == "main" || name == "master" {
-                    colours.branch_main().paint(name)
-                } else {
-                    colours.branch_other().paint(name)
-                }
-            }
+            Some(name) => match name.as_ref() {
+                "main" | "master" => colours.branch_main().paint(name),
+                _ => colours.branch_other().paint(name),
+            },
             None => colours.no_repo().paint("-"),
         };
 

+ 1 - 1
src/output/table.rs

@@ -224,7 +224,7 @@ impl Column {
             #[cfg(unix)]
             Self::Inode => "inode",
             Self::GitStatus => "Git",
-            Self::SubdirGitRepo(_) => "Repo",
+            Self::SubdirGitRepo(_) => "Git Repo",
             #[cfg(unix)]
             Self::Octal => "Octal",
             #[cfg(unix)]