Skip to content

Commit

Permalink
fix newline-trimming when getting current remote and revision
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Feb 15, 2022
1 parent 9ae22c3 commit 0295eea
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions helix-term/src/grammars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ pub fn fetch_grammar(grammar: GrammarConfiguration) {
}

// ensure the remote matches the configured remote
if get_repository_info(&grammar_dir, vec!["remote", "get-url", REMOTE_NAME])
!= Some(remote.clone())
{
if get_remote_url(&grammar_dir).map_or(false, |s| s.trim_end() == remote) {
set_remote(&grammar_dir, &remote);
}

// ensure the revision matches the configured revision
if get_repository_info(&grammar_dir, vec!["rev-parse", "HEAD"]) != Some(revision.clone()) {
if get_revision(&grammar_dir).map_or(false, |s| s.trim_end() == revision) {
// Fetch the exact revision from the remote.
// Supported by server-side git since v2.5.0 (July 2015),
// enabled by default on major git hosts.
Expand Down Expand Up @@ -117,9 +115,22 @@ fn set_remote(repository: &Path, remote_url: &str) {
}
}

fn get_repository_info(repository: &Path, args: Vec<&str>) -> Option<String> {
fn get_remote_url(repository: &Path) -> Option<String> {
let output = Command::new("git")
.args(args)
.args(["remote", "get-url", REMOTE_NAME])
.current_dir(repository)
.output()
.expect("Failed to execute 'git'");
if output.status.success() {
Some(String::from_utf8_lossy(output.stdout.as_slice()).into_owned())
} else {
None
}
}

fn get_revision(repository: &Path) -> Option<String> {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.current_dir(repository)
.output()
.expect("Failed to execute 'git'");
Expand Down

0 comments on commit 0295eea

Please sign in to comment.