Skip to content

Commit f5a4332

Browse files
committed
fix(init): set man page command names correctly
1 parent 113120e commit f5a4332

File tree

2 files changed

+141
-2
lines changed

2 files changed

+141
-2
lines changed

git-branchless-opts/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,11 @@ pub fn write_man_pages(man_dir: &Path) -> std::io::Result<()> {
900900
let man1_dir = man_dir.join("man1");
901901
std::fs::create_dir_all(&man1_dir)?;
902902

903-
let app = Opts::command();
903+
let app =
904+
// Explicitly set the name here, or else clap thinks that the name of the
905+
// command is `git-branchless-opts` (and that its subcommands are
906+
// `git-branchless-opts-amend`, etc.).
907+
Opts::command().name("git-branchless");
904908
generate_man_page(&man1_dir, "git-branchless", &app)?;
905909
for subcommand in app.get_subcommands() {
906910
let subcommand_exe_name = format!("git-branchless-{}", subcommand.get_name());
@@ -912,7 +916,14 @@ pub fn write_man_pages(man_dir: &Path) -> std::io::Result<()> {
912916
fn generate_man_page(man1_dir: &Path, name: &str, command: &ClapCommand) -> std::io::Result<()> {
913917
let rendered_man_page = {
914918
let mut buffer = Vec::new();
915-
clap_mangen::Man::new(command.clone()).render(&mut buffer)?;
919+
clap_mangen::Man::new(command.clone())
920+
// The rendered man-page command name would be the subcommand only
921+
// (such as `amend(1)` instead of `git-branchless-amend(1)`), so
922+
// override the name here. Also, the top-level man-page name will be
923+
// `git-branchless-opts(1)` instead of `git-branchless(1)`, which is
924+
// also handled by this call to `.title`.
925+
.title(name)
926+
.render(&mut buffer)?;
916927
buffer
917928
};
918929
let output_path = man1_dir.join(format!("{name}.1"));

git-branchless/tests/test_init.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,131 @@ fn test_init_worktree() -> eyre::Result<()> {
633633

634634
Ok(())
635635
}
636+
637+
#[test]
638+
fn test_install_man_pages() -> eyre::Result<()> {
639+
let git = make_git()?;
640+
git.init_repo()?;
641+
let dir = "foo";
642+
git.branchless("install-man-pages", &[dir])?;
643+
let man_page_contents = std::fs::read(
644+
git.repo_path
645+
.join(dir)
646+
.join("man1")
647+
.join("git-branchless.1"),
648+
)?;
649+
let man_page_contents = String::from_utf8_lossy(&man_page_contents);
650+
insta::assert_snapshot!(man_page_contents, @r###"
651+
.ie \n(.g .ds Aq \(aq
652+
.el .ds Aq '
653+
.TH git-branchless 1 "git-branchless 0.7.0"
654+
.SH NAME
655+
git\-branchless \- Branchless workflow for Git
656+
.SH SYNOPSIS
657+
\fBgit\-branchless\fR [\fB\-C \fR] [\fB\-\-color\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] <\fIsubcommands\fR>
658+
.SH DESCRIPTION
659+
Branchless workflow for Git.
660+
.PP
661+
See the documentation at <https://github.com/arxanas/git\-branchless/wiki>.
662+
.SH OPTIONS
663+
.TP
664+
\fB\-C\fR=\fIWORKING_DIRECTORY\fR
665+
Change to the given directory before executing the rest of the program. (The option is called `\-C` for symmetry with Git.)
666+
.TP
667+
\fB\-\-color\fR=\fICOLOR\fR
668+
Flag to force enable or disable terminal colors
669+
.br
670+
671+
.br
672+
\fIPossible values:\fR
673+
.RS 14
674+
.IP \(bu 2
675+
auto: Automatically determine whether to display colors from the terminal and environment variables. This is the default behavior
676+
.IP \(bu 2
677+
always: Always display terminal colors
678+
.IP \(bu 2
679+
never: Never display terminal colors
680+
.RE
681+
.TP
682+
\fB\-h\fR, \fB\-\-help\fR
683+
Print help information (use `\-h` for a summary)
684+
.TP
685+
\fB\-V\fR, \fB\-\-version\fR
686+
Print version information
687+
.SH SUBCOMMANDS
688+
.TP
689+
git\-branchless\-amend(1)
690+
Amend the current HEAD commit
691+
.TP
692+
git\-branchless\-bug\-report(1)
693+
Gather information about recent operations to upload as part of a bug report
694+
.TP
695+
git\-branchless\-gc(1)
696+
Run internal garbage collection
697+
.TP
698+
git\-branchless\-hide(1)
699+
Hide the provided commits from the smartlog
700+
.TP
701+
git\-branchless\-init(1)
702+
Initialize the branchless workflow for this repository
703+
.TP
704+
git\-branchless\-install\-man\-pages(1)
705+
Install git\-branchless\*(Aqs man\-pages to the given path
706+
.TP
707+
git\-branchless\-move(1)
708+
Move a subtree of commits from one location to another
709+
.TP
710+
git\-branchless\-next(1)
711+
Move to a later commit in the current stack
712+
.TP
713+
git\-branchless\-prev(1)
714+
Move to an earlier commit in the current stack
715+
.TP
716+
git\-branchless\-query(1)
717+
Query the commit graph using the "revset" language and print matching commits
718+
.TP
719+
git\-branchless\-repair(1)
720+
Restore internal invariants by reconciling the internal operation log with the state of the Git repository
721+
.TP
722+
git\-branchless\-restack(1)
723+
Fix up commits abandoned by a previous rewrite operation
724+
.TP
725+
git\-branchless\-record(1)
726+
Create a commit by interactively selecting which changes to include
727+
.TP
728+
git\-branchless\-reword(1)
729+
Reword commits
730+
.TP
731+
git\-branchless\-smartlog(1)
732+
`smartlog` command
733+
.TP
734+
git\-branchless\-submit(1)
735+
Push commits to a remote
736+
.TP
737+
git\-branchless\-switch(1)
738+
Switch to the provided branch or commit
739+
.TP
740+
git\-branchless\-sync(1)
741+
Move any local commit stacks on top of the main branch
742+
.TP
743+
git\-branchless\-test(1)
744+
Run a command on each commit in a given set and aggregate the results
745+
.TP
746+
git\-branchless\-undo(1)
747+
Browse or return to a previous state of the repository
748+
.TP
749+
git\-branchless\-unhide(1)
750+
Unhide previously\-hidden commits from the smartlog
751+
.TP
752+
git\-branchless\-wrap(1)
753+
Wrap a Git command inside a branchless transaction
754+
.TP
755+
git\-branchless\-help(1)
756+
Print this message or the help of the given subcommand(s)
757+
.SH VERSION
758+
v0.7.0
759+
.SH AUTHORS
760+
Waleed Khan <me@waleedkhan.name>
761+
"###);
762+
Ok(())
763+
}

0 commit comments

Comments
 (0)