forked from foriequal0/git-trim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide porcelain output for scripts.
Options: * local branches * remote branches * JSON output. \foriequal0#138
- Loading branch information
Showing
9 changed files
with
321 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,53 @@ | ||
use anyhow::Result; | ||
use git2::Repository; | ||
|
||
use crate::TrimPlan; | ||
|
||
/// Prints all locally to-be-deleted branches. | ||
pub fn print_local( | ||
plan: &TrimPlan, | ||
_repo: &Repository, | ||
mut writer: impl std::io::Write, | ||
) -> Result<()> { | ||
let mut merged_locals = Vec::new(); | ||
for branch in &plan.to_delete { | ||
if let Some(local) = branch.local() { | ||
merged_locals.push(local.short_name().to_owned()); | ||
} | ||
} | ||
|
||
merged_locals.sort(); | ||
for branch in merged_locals { | ||
writeln!(writer, "{}", branch)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Print all remotely to-be-deleted branches in the form "<remote>/<branch_name>" | ||
pub fn print_remote( | ||
plan: &TrimPlan, | ||
repo: &Repository, | ||
mut writer: impl std::io::Write, | ||
) -> Result<()> { | ||
let mut merged_remotes = Vec::new(); | ||
for branch in &plan.to_delete { | ||
if let Some(remote) = branch.remote(repo)? { | ||
merged_remotes.push(remote); | ||
} | ||
} | ||
|
||
merged_remotes.sort(); | ||
for branch in merged_remotes { | ||
let branch_name = &branch.refname["/refs/heads".len()..]; | ||
writeln!(writer, "{}/{}", branch.remote, branch_name)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn print_json(plan: &TrimPlan, _repo: &Repository, writer: impl std::io::Write) -> Result<()> { | ||
serde_json::to_writer(writer, &plan)?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.