Skip to content

Commit 5970e72

Browse files
authored
Merge pull request #79 from epage/rename
fix!: Rename `git-branch-backup` to `git-branch-stash`
2 parents 032bd26 + fb5dc9c commit 5970e72

File tree

8 files changed

+80
-76
lines changed

8 files changed

+80
-76
lines changed

src/bin/git-branch-backup/args.rs renamed to src/bin/git-branch-stash/args.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,65 @@ pub struct Args {
2121

2222
#[derive(structopt::StructOpt)]
2323
pub enum Subcommand {
24-
/// Backup all branches
24+
/// Stash all branches
2525
Push(PushArgs),
26-
/// List all backups
26+
/// List all stashed snapshots
2727
List(ListArgs),
28-
/// Clear all backups
28+
/// Clear all snapshots
2929
Clear(ClearArgs),
30-
/// Delete the last backup
30+
/// Delete the last snapshot
3131
Drop(DropArgs),
32-
/// Apply the last backup, deleting it
32+
/// Apply the last snapshot, deleting it
3333
Pop(PopArgs),
34-
/// Apply the last backup
34+
/// Apply the last snapshot
3535
Apply(ApplyArgs),
36-
/// List all backup stacks
36+
/// List all snapshot stacks
3737
Stacks(StacksArgs),
3838
}
3939

4040
#[derive(structopt::StructOpt)]
4141
pub struct PushArgs {
42-
/// Specify which backup stack to use
43-
#[structopt(default_value = git_stack::backup::Stack::DEFAULT_STACK)]
42+
/// Specify which stash stack to use
43+
#[structopt(default_value = git_stack::stash::Stack::DEFAULT_STACK)]
4444
pub stack: String,
4545

46-
/// Annotate the backup with the given message
46+
/// Annotate the snapshot with the given message
4747
#[structopt(short, long)]
4848
pub message: Option<String>,
4949
}
5050

5151
#[derive(structopt::StructOpt)]
5252
pub struct ListArgs {
53-
/// Specify which backup stack to use
54-
#[structopt(default_value = git_stack::backup::Stack::DEFAULT_STACK)]
53+
/// Specify which stash stack to use
54+
#[structopt(default_value = git_stack::stash::Stack::DEFAULT_STACK)]
5555
pub stack: String,
5656
}
5757

5858
#[derive(structopt::StructOpt)]
5959
pub struct ClearArgs {
60-
/// Specify which backup stack to use
61-
#[structopt(default_value = git_stack::backup::Stack::DEFAULT_STACK)]
60+
/// Specify which stash stack to use
61+
#[structopt(default_value = git_stack::stash::Stack::DEFAULT_STACK)]
6262
pub stack: String,
6363
}
6464

6565
#[derive(structopt::StructOpt)]
6666
pub struct DropArgs {
67-
/// Specify which backup stack to use
68-
#[structopt(default_value = git_stack::backup::Stack::DEFAULT_STACK)]
67+
/// Specify which stash stack to use
68+
#[structopt(default_value = git_stack::stash::Stack::DEFAULT_STACK)]
6969
pub stack: String,
7070
}
7171

7272
#[derive(structopt::StructOpt)]
7373
pub struct PopArgs {
74-
/// Specify which backup stack to use
75-
#[structopt(default_value = git_stack::backup::Stack::DEFAULT_STACK)]
74+
/// Specify which stash stack to use
75+
#[structopt(default_value = git_stack::stash::Stack::DEFAULT_STACK)]
7676
pub stack: String,
7777
}
7878

7979
#[derive(structopt::StructOpt)]
8080
pub struct ApplyArgs {
81-
/// Specify which backup stack to use
82-
#[structopt(default_value = git_stack::backup::Stack::DEFAULT_STACK)]
81+
/// Specify which stash stack to use
82+
#[structopt(default_value = git_stack::stash::Stack::DEFAULT_STACK)]
8383
pub stack: String,
8484
}
8585

src/bin/git-branch-backup/main.rs renamed to src/bin/git-branch-stash/main.rs

+31-27
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn push(args: args::PushArgs) -> proc_exit::ExitResult {
4949
let cwd = std::env::current_dir().with_code(proc_exit::Code::USAGE_ERR)?;
5050
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
5151
let repo = git_stack::git::GitRepo::new(repo);
52-
let mut stack = git_stack::backup::Stack::new(&args.stack, &repo);
52+
let mut stack = git_stack::stash::Stack::new(&args.stack, &repo);
5353

5454
let repo_config = git_stack::config::RepoConfig::from_all(repo.raw())
5555
.with_code(proc_exit::Code::CONFIG_ERR)?;
@@ -66,13 +66,13 @@ fn push(args: args::PushArgs) -> proc_exit::ExitResult {
6666
log::warn!("Working tree is dirty, only capturing committed changes");
6767
}
6868

69-
let mut backup =
70-
git_stack::backup::Backup::from_repo(&repo).with_code(proc_exit::Code::FAILURE)?;
69+
let mut snapshot =
70+
git_stack::stash::Snapshot::from_repo(&repo).with_code(proc_exit::Code::FAILURE)?;
7171
if let Some(message) = args.message.as_deref() {
72-
backup.insert_message(message);
72+
snapshot.insert_message(message);
7373
}
74-
backup.insert_parent(&repo, &branches, &protected_branches);
75-
stack.push(backup)?;
74+
snapshot.insert_parent(&repo, &branches, &protected_branches);
75+
stack.push(snapshot)?;
7676

7777
Ok(())
7878
}
@@ -87,23 +87,27 @@ fn list(args: args::ListArgs, colored: bool) -> proc_exit::ExitResult {
8787
let cwd = std::env::current_dir().with_code(proc_exit::Code::USAGE_ERR)?;
8888
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
8989
let repo = git_stack::git::GitRepo::new(repo);
90-
let stack = git_stack::backup::Stack::new(&args.stack, &repo);
90+
let stack = git_stack::stash::Stack::new(&args.stack, &repo);
9191

92-
let backups: Vec<_> = stack.iter().collect();
93-
for (i, backup_path) in backups.iter().enumerate() {
94-
let style = if i < backups.len() - 1 {
92+
let snapshots: Vec<_> = stack.iter().collect();
93+
for (i, snapshot_path) in snapshots.iter().enumerate() {
94+
let style = if i < snapshots.len() - 1 {
9595
palette.info
9696
} else {
9797
palette.good
9898
};
99-
let backup = match git_stack::backup::Backup::load(backup_path) {
100-
Ok(backup) => backup,
99+
let snapshot = match git_stack::stash::Snapshot::load(snapshot_path) {
100+
Ok(snapshot) => snapshot,
101101
Err(err) => {
102-
log::error!("Failed to load backup {}: {}", backup_path.display(), err);
102+
log::error!(
103+
"Failed to load snapshot {}: {}",
104+
snapshot_path.display(),
105+
err
106+
);
103107
continue;
104108
}
105109
};
106-
match backup.metadata.get("message") {
110+
match snapshot.metadata.get("message") {
107111
Some(message) => {
108112
writeln!(
109113
std::io::stdout(),
@@ -115,11 +119,11 @@ fn list(args: args::ListArgs, colored: bool) -> proc_exit::ExitResult {
115119
writeln!(
116120
std::io::stdout(),
117121
"{}",
118-
style.paint(format_args!("Path: {}", backup_path.display()))
122+
style.paint(format_args!("Path: {}", snapshot_path.display()))
119123
)?;
120124
}
121125
}
122-
for branch in backup.branches.iter() {
126+
for branch in snapshot.branches.iter() {
123127
let summary = if let Some(summary) = branch.metadata.get("summary") {
124128
summary.to_string()
125129
} else {
@@ -177,7 +181,7 @@ fn clear(args: args::ClearArgs) -> proc_exit::ExitResult {
177181
let cwd = std::env::current_dir().with_code(proc_exit::Code::USAGE_ERR)?;
178182
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
179183
let repo = git_stack::git::GitRepo::new(repo);
180-
let mut stack = git_stack::backup::Stack::new(&args.stack, &repo);
184+
let mut stack = git_stack::stash::Stack::new(&args.stack, &repo);
181185

182186
stack.clear();
183187

@@ -188,7 +192,7 @@ fn drop(args: args::DropArgs) -> proc_exit::ExitResult {
188192
let cwd = std::env::current_dir().with_code(proc_exit::Code::USAGE_ERR)?;
189193
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
190194
let repo = git_stack::git::GitRepo::new(repo);
191-
let mut stack = git_stack::backup::Stack::new(&args.stack, &repo);
195+
let mut stack = git_stack::stash::Stack::new(&args.stack, &repo);
192196

193197
stack.pop();
194198

@@ -199,17 +203,17 @@ fn pop(args: args::PopArgs) -> proc_exit::ExitResult {
199203
let cwd = std::env::current_dir().with_code(proc_exit::Code::USAGE_ERR)?;
200204
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
201205
let mut repo = git_stack::git::GitRepo::new(repo);
202-
let mut stack = git_stack::backup::Stack::new(&args.stack, &repo);
206+
let mut stack = git_stack::stash::Stack::new(&args.stack, &repo);
203207

204208
if repo.is_dirty() {
205209
return Err(proc_exit::Code::USAGE_ERR.with_message("Working tree is dirty, aborting"));
206210
}
207211

208212
match stack.peek() {
209213
Some(last) => {
210-
let backup =
211-
git_stack::backup::Backup::load(&last).with_code(proc_exit::Code::FAILURE)?;
212-
backup
214+
let snapshot =
215+
git_stack::stash::Snapshot::load(&last).with_code(proc_exit::Code::FAILURE)?;
216+
snapshot
213217
.apply(&mut repo)
214218
.with_code(proc_exit::Code::FAILURE)?;
215219
let _ = std::fs::remove_file(&last);
@@ -226,17 +230,17 @@ fn apply(args: args::ApplyArgs) -> proc_exit::ExitResult {
226230
let cwd = std::env::current_dir().with_code(proc_exit::Code::USAGE_ERR)?;
227231
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
228232
let mut repo = git_stack::git::GitRepo::new(repo);
229-
let mut stack = git_stack::backup::Stack::new(&args.stack, &repo);
233+
let mut stack = git_stack::stash::Stack::new(&args.stack, &repo);
230234

231235
if repo.is_dirty() {
232236
return Err(proc_exit::Code::USAGE_ERR.with_message("Working tree is dirty, aborting"));
233237
}
234238

235239
match stack.peek() {
236240
Some(last) => {
237-
let backup =
238-
git_stack::backup::Backup::load(&last).with_code(proc_exit::Code::FAILURE)?;
239-
backup
241+
let snapshot =
242+
git_stack::stash::Snapshot::load(&last).with_code(proc_exit::Code::FAILURE)?;
243+
snapshot
240244
.apply(&mut repo)
241245
.with_code(proc_exit::Code::FAILURE)?;
242246
}
@@ -253,7 +257,7 @@ fn stacks(_args: args::StacksArgs) -> proc_exit::ExitResult {
253257
let repo = git2::Repository::discover(&cwd).with_code(proc_exit::Code::USAGE_ERR)?;
254258
let repo = git_stack::git::GitRepo::new(repo);
255259

256-
for stack in git_stack::backup::Stack::all(&repo) {
260+
for stack in git_stack::stash::Stack::all(&repo) {
257261
writeln!(std::io::stdout(), "{}", stack.name)?;
258262
}
259263

src/bin/git-stack/stack.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct State {
1717
pull: bool,
1818
push: bool,
1919
dry_run: bool,
20-
backup_capacity: Option<usize>,
20+
snapshot_capacity: Option<usize>,
2121

2222
show_format: git_stack::config::Format,
2323
show_stacked: bool,
@@ -44,7 +44,7 @@ impl State {
4444
)
4545
.with_code(proc_exit::Code::CONFIG_ERR)?;
4646
let dry_run = args.dry_run;
47-
let backup_capacity = repo_config.capacity();
47+
let snapshot_capacity = repo_config.capacity();
4848

4949
let show_format = repo_config.show_format();
5050
let show_stacked = repo_config.show_stacked();
@@ -156,7 +156,7 @@ impl State {
156156
pull,
157157
push,
158158
dry_run,
159-
backup_capacity,
159+
snapshot_capacity,
160160

161161
show_format,
162162
show_stacked,
@@ -272,21 +272,21 @@ pub fn stack(args: &crate::args::Args, colored_stdout: bool) -> proc_exit::ExitR
272272
}
273273
}
274274

275-
const BACKUP_NAME: &str = "git-stack";
275+
const STASH_STACK_NAME: &str = "git-stack";
276276
let mut success = true;
277277
let mut backed_up = false;
278278
if state.rebase {
279279
if state.repo.is_dirty() {
280280
return Err(proc_exit::Code::USAGE_ERR.with_message("Working tree is dirty, aborting"));
281281
}
282282

283-
let mut backups = git_stack::backup::Stack::new(BACKUP_NAME, &state.repo);
284-
backups.capacity(state.backup_capacity);
285-
let mut backup = git_stack::backup::Backup::from_repo(&state.repo)
283+
let mut snapshots = git_stack::stash::Stack::new(STASH_STACK_NAME, &state.repo);
284+
snapshots.capacity(state.snapshot_capacity);
285+
let mut snapshot = git_stack::stash::Snapshot::from_repo(&state.repo)
286286
.with_code(proc_exit::Code::FAILURE)?;
287-
backup.insert_parent(&state.repo, &state.branches, &state.protected_branches);
287+
snapshot.insert_parent(&state.repo, &state.branches, &state.protected_branches);
288288
if !state.dry_run {
289-
backups.push(backup)?;
289+
snapshots.push(snapshot)?;
290290
backed_up = true;
291291
}
292292

@@ -328,7 +328,7 @@ pub fn stack(args: &crate::args::Args, colored_stdout: bool) -> proc_exit::ExitR
328328
show(&state, colored_stdout).with_code(proc_exit::Code::FAILURE)?;
329329

330330
if backed_up {
331-
log::info!("To undo, run `git branch-backup pop {}`", BACKUP_NAME);
331+
log::info!("To undo, run `git branch-stash pop {}`", STASH_STACK_NAME);
332332
}
333333

334334
if !success {

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static PUSH_REMOTE_FIELD: &str = "stack.push-remote";
1919
static PULL_REMOTE_FIELD: &str = "stack.pull-remote";
2020
static FORMAT_FIELD: &str = "stack.show-format";
2121
static STACKED_FIELD: &str = "stack.show-stacked";
22-
static BACKUP_CAPACITY_FIELD: &str = "branch-backup.capacity";
22+
static BACKUP_CAPACITY_FIELD: &str = "branch-stash.capacity";
2323

2424
static DEFAULT_PROTECTED_BRANCHES: [&str; 4] = ["main", "master", "dev", "stable"];
2525
const DEFAULT_CAPACITY: usize = 30;

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#[macro_use]
44
extern crate clap;
55

6-
pub mod backup;
76
pub mod config;
87
pub mod git;
98
pub mod graph;
109
pub mod log;
10+
pub mod stash;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[allow(clippy::module_inception)]
2-
mod backup;
2+
mod snapshot;
33
mod stack;
44

5-
pub use backup::*;
5+
pub use snapshot::*;
66
pub use stack::*;

src/backup/backup.rs renamed to src/stash/snapshot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
2-
pub struct Backup {
2+
pub struct Snapshot {
33
pub branches: Vec<Branch>,
44
#[serde(default)]
55
#[serde(skip_serializing_if = "std::collections::BTreeMap::is_empty")]
66
pub metadata: std::collections::BTreeMap<String, serde_json::Value>,
77
}
88

9-
impl Backup {
9+
impl Snapshot {
1010
pub fn load(path: &std::path::Path) -> Result<Self, std::io::Error> {
1111
let file = std::fs::File::open(path)?;
1212
let reader = std::io::BufReader::new(file);

0 commit comments

Comments
 (0)