-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the default target branch based on
init.defaultBranch
Fixes #6.
- Loading branch information
Showing
3 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use git_commands::git; | ||
|
||
use crate::trim::TrimAsciiWhitespace; | ||
|
||
/// Get the default branch name from Git config's `init.defaultBranch` setting, | ||
/// falling back to 'master' if it isn't set. This should help handle default | ||
/// branch names that are more awoke. | ||
pub fn default_branch_name(for_path: &Path) -> Result<String> { | ||
let output = git( | ||
&[ | ||
"--no-pager", | ||
"config", | ||
"--default", | ||
"master", | ||
"--get", | ||
"init.defaultBranch", | ||
], | ||
for_path, | ||
)? | ||
.stdout; | ||
let output = std::str::from_utf8(output.trim_ascii_whitespace())?; | ||
Ok(output.to_owned()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters