Skip to content

Commit adfe454

Browse files
committed
feat(init): add -b/--branch option
1 parent 103f5f8 commit adfe454

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

completion/stgit.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ _stg-import() {
732732
_stg-init() {
733733
local -a subcmd_args
734734
__stg_add_args_help
735+
__stg_add_args_branch
735736
_arguments -s $subcmd_args
736737
}
737738

src/cmd/init.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use anyhow::Result;
66
use clap::ArgMatches;
77

88
use crate::{
9+
argset,
10+
branchloc::BranchLocator,
911
ext::RepositoryExtended,
1012
stack::{InitializationPolicy, Stack},
1113
};
@@ -19,25 +21,36 @@ pub(super) const STGIT_COMMAND: super::StGitCommand = super::StGitCommand {
1921

2022
fn make() -> clap::Command {
2123
clap::Command::new(STGIT_COMMAND.name)
22-
.about("Initialize a StGit stack on current branch")
24+
.about("Initialize a StGit stack on a branch")
2325
.long_about(
24-
"Initialize a StGit stack on the current branch.\n\
26+
"Initialize a StGit stack on a branch.\n\
2527
\n\
26-
A branch must be initialized with a StGit stack before patches may be \
27-
created with 'stg new', imported with 'stg import', or picked with 'stg \
28-
pick'.\n\
28+
Initializing a branch with a StGit stack commits initial, empty stack \
29+
state for the branch to the repository. Theses stack metadata commits are \
30+
tracked by the `refs/stacks/<branch>` reference. Updated stack state is \
31+
committed by each StGit command that modifies the stack. StGit users do \
32+
not have to do anything with the `refs/stacks/<branch>` ref directly.\n\
2933
\n\
30-
The branch and its git repository must already exist and contain at least \
31-
one commit before initializing a StGit stack. Branches created with `stg \
32-
branch --create` are automatically initialized.\n\
34+
Some StGit commands, such as `stg new` and `stg uncommit`, will \
35+
automatically initialize the stack, so it is often not necessary to \
36+
explicitly initialize the stack on a branch. Also, branches created with \
37+
`stg branch --create` are automatically initialized.\n\
38+
\n\
39+
The branch must already exist and point to a commit before initializing a \
40+
StGit stack.\n\
3341
\n\
3442
StGit stack metadata can be deinitialized from a branch using `stg branch \
3543
--cleanup`. See 'stg branch' for more details.",
3644
)
45+
.arg(argset::branch_arg())
3746
}
3847

39-
fn run(_: &ArgMatches) -> Result<()> {
48+
fn run(matches: &ArgMatches) -> Result<()> {
4049
let repo = gix::Repository::open()?;
41-
Stack::current(&repo, InitializationPolicy::MustInitialize)?;
50+
Stack::from_branch_locator(
51+
&repo,
52+
matches.get_one::<BranchLocator>("branch"),
53+
InitializationPolicy::MustInitialize,
54+
)?;
4255
Ok(())
4356
}

0 commit comments

Comments
 (0)