From a1de322203c38df2845c205dd5f573dd0a19700f Mon Sep 17 00:00:00 2001 From: lrlna Date: Tue, 9 Feb 2021 15:56:21 +0100 Subject: [PATCH 1/3] separate out git_context.branch test for troubleshooting --- src/utils/git.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/git.rs b/src/utils/git.rs index 006c4785a..9accddcae 100644 --- a/src/utils/git.rs +++ b/src/utils/git.rs @@ -335,11 +335,17 @@ mod tests { // so, for now, skip this test on nightly! #[rustversion::stable] #[test] - fn it_can_create_git_context() { + fn it_can_create_git_context_with_branch() { let git_context = GitContext::try_from_rover_env(&RoverEnv::new()).expect("Could not create git context"); assert!(git_context.branch.is_some()); + } + #[test] + fn it_can_create_git_context_committ_committer_remote_url() { + let git_context = + GitContext::try_from_rover_env(&RoverEnv::new()).expect("Could not create git context"); + assert!(git_context.committer.is_some()); if let Some(commit) = git_context.commit { From 456bc8efe065a85deafa9ee1f024c3d6d583321f Mon Sep 17 00:00:00 2001 From: lrlna Date: Tue, 9 Feb 2021 16:24:28 +0100 Subject: [PATCH 2/3] troubleshoot again on nightly --- src/utils/git.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/git.rs b/src/utils/git.rs index 9accddcae..b6298ad7f 100644 --- a/src/utils/git.rs +++ b/src/utils/git.rs @@ -333,7 +333,6 @@ mod tests { // for some reason we cannot detect the branch with nightly rust // so, for now, skip this test on nightly! - #[rustversion::stable] #[test] fn it_can_create_git_context_with_branch() { let git_context = From e030e900d50b64c14d38c3fe1a04695edb264a04 Mon Sep 17 00:00:00 2001 From: lrlna Date: Tue, 9 Feb 2021 16:36:40 +0100 Subject: [PATCH 3/3] fix(rover): git context should also work for tags We should always return repo.head.shorthand when creating a branch for GitContext. This will ensure that 'branch' is an available property for pushed tags. --- src/utils/git.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/utils/git.rs b/src/utils/git.rs index b6298ad7f..9de2e0aac 100644 --- a/src/utils/git.rs +++ b/src/utils/git.rs @@ -39,9 +39,7 @@ impl GitContext { Ok(env.get(RoverEnvKey::VcsBranch)?.or_else(|| { let mut branch = None; if let Some(head) = head { - if head.is_branch() { - branch = head.shorthand().map(|s| s.to_string()) - } + branch = head.shorthand().map(|s| s.to_string()) } branch })) @@ -331,20 +329,12 @@ mod tests { assert_eq!(expected_git_context, actual_git_context); } - // for some reason we cannot detect the branch with nightly rust - // so, for now, skip this test on nightly! - #[test] - fn it_can_create_git_context_with_branch() { - let git_context = - GitContext::try_from_rover_env(&RoverEnv::new()).expect("Could not create git context"); - - assert!(git_context.branch.is_some()); - } #[test] fn it_can_create_git_context_committ_committer_remote_url() { let git_context = GitContext::try_from_rover_env(&RoverEnv::new()).expect("Could not create git context"); + assert!(git_context.branch.is_some()); assert!(git_context.committer.is_some()); if let Some(commit) = git_context.commit {