Skip to content

Commit eff57eb

Browse files
authored
Merge pull request #60 from epage/fix
fix(graph): Allow merging after marking protected
2 parents 6d16363 + ea222fb commit eff57eb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
<!-- next-header -->
88
## [Unreleased] - ReleaseDate
99

10+
#### Fixes
11+
12+
- Stack View:
13+
- Ensure protected commits are hidden when showing multiple protected branches
14+
1015
## [0.2.6] - 2021-09-01
1116

1217
#### Fixes

src/bin/git-stack/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl State {
8585
}]
8686
}
8787
(None, None, git_stack::config::Stack::All) => {
88-
let mut stack_branches = std::collections::HashMap::new();
88+
let mut stack_branches = std::collections::BTreeMap::new();
8989
for (branch_id, branch) in branches.iter() {
9090
let base_branch =
9191
resolve_implicit_base(&repo, branch_id, &branches, &protected_branches)

src/graph/node.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::collections::HashMap;
1+
use std::collections::BTreeMap;
22

33
#[derive(Clone, Debug, PartialEq, Eq)]
44
pub struct Node {
55
pub local_commit: std::rc::Rc<crate::git::Commit>,
66
pub branches: Vec<crate::git::Branch>,
77
pub action: crate::graph::Action,
88
pub pushable: bool,
9-
pub children: HashMap<git2::Oid, Node>,
9+
pub children: BTreeMap<git2::Oid, Node>,
1010
}
1111

1212
impl Node {
@@ -17,7 +17,7 @@ impl Node {
1717
let branches = possible_branches
1818
.remove(local_commit.id)
1919
.unwrap_or_else(Vec::new);
20-
let children = HashMap::new();
20+
let children = BTreeMap::new();
2121
Self {
2222
local_commit,
2323
branches,
@@ -59,8 +59,13 @@ impl Node {
5959
.ok_or_else(|| eyre::eyre!("Could not find merge base"))?;
6060

6161
if merge_base_id != self.local_commit.id {
62-
let prefix =
63-
Node::populate(repo, merge_base_id, self.local_commit.id, possible_branches)?;
62+
let prefix = Node::populate(
63+
repo,
64+
merge_base_id,
65+
self.local_commit.id,
66+
possible_branches,
67+
self.action,
68+
)?;
6469
self = prefix.extend(repo, self)?;
6570
}
6671

@@ -69,6 +74,7 @@ impl Node {
6974
self.local_commit.id,
7075
local_commit.id,
7176
possible_branches,
77+
crate::graph::Action::Pick,
7278
)?;
7379
self.merge(other);
7480

@@ -106,6 +112,7 @@ impl Node {
106112
merge_base_id,
107113
self.local_commit.id,
108114
&mut possible_branches,
115+
self.action,
109116
)?;
110117
self = prefix.extend(repo, self)?;
111118
}
@@ -115,6 +122,7 @@ impl Node {
115122
merge_base_id,
116123
other.local_commit.id,
117124
&mut possible_branches,
125+
other.action,
118126
)?;
119127
other = prefix.extend(repo, other)?;
120128
}
@@ -129,6 +137,7 @@ impl Node {
129137
base_oid: git2::Oid,
130138
head_oid: git2::Oid,
131139
branches: &mut crate::git::Branches,
140+
default_action: crate::graph::Action,
132141
) -> Result<Self, git2::Error> {
133142
if let Some(head_branches) = branches.get(head_oid) {
134143
let head_name = head_branches.first().unwrap().name.as_str();
@@ -153,6 +162,7 @@ impl Node {
153162

154163
let head_commit = repo.find_commit(head_oid).unwrap();
155164
let mut root = Node::new(head_commit, branches);
165+
root.action = default_action;
156166

157167
let mut commits = repo.commits_from(head_oid);
158168
// Already added head_oid
@@ -163,6 +173,7 @@ impl Node {
163173
for commit in commits {
164174
let child = root;
165175
root = Node::new(commit, branches);
176+
root.action = default_action;
166177
root.children.insert(child.local_commit.id, child);
167178
if root.local_commit.id == base_oid {
168179
break;

0 commit comments

Comments
 (0)