Skip to content

Commit 13b5c1d

Browse files
feat: add git blame (You) logic
this commit suffixes (You) to the git blame author if `git config user.name` is same as author name `get_git_user_name` fetches user.name `for_path` method is modified to append (You) at the end of entry.author if author == username
1 parent 2a23db6 commit 13b5c1d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

crates/git/src/blame.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ impl Blame {
3636
let mut entries = parse_git_blame(&output)?;
3737
entries.sort_unstable_by(|a, b| a.range.start.cmp(&b.range.start));
3838

39+
let current_user = get_git_user_name(git_binary, working_directory)?;
40+
41+
if let Some(username) = current_user {
42+
for entry in &mut entries {
43+
if let Some(ref author) = entry.author {
44+
if author == &username {
45+
entry.author = Some(format!("{} (You)", author));
46+
}
47+
}
48+
}
49+
}
50+
3951
let mut permalinks = HashMap::default();
4052
let mut unique_shas = HashSet::default();
4153
let parsed_remote_url = remote_url
@@ -119,6 +131,21 @@ fn run_git_blame(
119131
Ok(String::from_utf8(output.stdout)?)
120132
}
121133

134+
fn get_git_user_name(git_binary: &Path, working_directory: &Path) -> Result<Option<String>> {
135+
let output = std::process::Command::new(git_binary)
136+
.current_dir(working_directory)
137+
.arg("config")
138+
.arg("user.name")
139+
.output()?;
140+
141+
if output.status.success() {
142+
let name = String::from_utf8(output.stdout)?;
143+
Ok(Some(name.trim().to_string()))
144+
} else {
145+
Ok(None)
146+
}
147+
}
148+
122149
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
123150
pub struct BlameEntry {
124151
pub sha: Oid,

0 commit comments

Comments
 (0)