Skip to content

Commit 3373eee

Browse files
quodlibetorBrandon W Maister
andauthored
ui: Show messages for ref updates (#31)
Co-authored-by: Brandon W Maister <[email protected]>
1 parent f2652ef commit 3373eee

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# Version 0.2.4
44

5-
* Retarget multiple branches pointing at the same commit
5+
* Retarget multiple branches pointing at the same commit, eg:
6+
> updated branch my-cool-branch: deadbeef -> c0ffee
67
78
# Version 0.2.3
89

src/lib.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ fn apply_diff_in_rebase(
134134
let rewrit_id = target_commit.amend(None, None, None, None, None, Some(&tree))?;
135135
let rewrit_object = repo.find_object(rewrit_id, None)?;
136136
let rewrit_commit_id = repo.find_commit(rewrit_object.id())?.id();
137-
branches.retarget_branches(target_commit.id(), rewrit_commit_id, rebase)?;
137+
let retargeted =
138+
branches.retarget_branches(target_commit.id(), rewrit_commit_id, rebase)?;
139+
for b in retargeted {
140+
println!("{}", b);
141+
}
138142

139143
repo.reset(&rewrit_object, git2::ResetType::Soft, None)?;
140144
}
@@ -162,7 +166,10 @@ fn do_rebase_inner(
162166
let message = commit.message();
163167
if message.is_some() && message != fixup_message {
164168
let new_id = rebase.commit(None, &sig, None)?;
165-
branches.retarget_branches(commit.id(), new_id, rebase)?;
169+
let retargeted = branches.retarget_branches(commit.id(), new_id, rebase)?;
170+
for b in retargeted {
171+
println!("{}", b);
172+
}
166173
}
167174
}
168175
Some(Fixup) | Some(Squash) | Some(Exec) | Some(Edit) | Some(Reword) => {
@@ -178,6 +185,21 @@ fn do_rebase_inner(
178185

179186
struct RepoBranches<'a>(HashMap<Oid, Vec<Branch<'a>>>);
180187

188+
struct RetargetedBranch {
189+
name: String,
190+
from: Oid,
191+
to: Oid,
192+
}
193+
194+
impl std::fmt::Display for RetargetedBranch {
195+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
196+
let from = &self.from.to_string()[..15];
197+
let to = &self.to.to_string()[..15];
198+
let name = &self.name;
199+
f.write_fmt(format_args!("updated branch {name}: {from} -> {to}"))
200+
}
201+
}
202+
181203
impl<'a> RepoBranches<'a> {
182204
fn for_repo(repo: &'a Repository) -> Result<RepoBranches<'a>, anyhow::Error> {
183205
let mut branches: HashMap<Oid, Vec<Branch>> = HashMap::new();
@@ -194,18 +216,28 @@ impl<'a> RepoBranches<'a> {
194216
original_commit: Oid,
195217
target_commit: Oid,
196218
rebase: &mut Rebase<'_>,
197-
) -> Result<(), anyhow::Error> {
219+
) -> Result<Vec<RetargetedBranch>, anyhow::Error> {
220+
let mut retargeted = vec![];
198221
if let Some(branches) = self.0.get_mut(&original_commit) {
199222
// Don't retarget the last branch, rebase.finish does that for us
200223
if rebase.operation_current() != Some(rebase.len() - 1) {
201224
for branch in branches.iter_mut() {
225+
retargeted.push(RetargetedBranch {
226+
name: branch
227+
.name()
228+
.context("getting a branch name")?
229+
.ok_or(anyhow!("branch should have a name"))?
230+
.to_owned(),
231+
from: original_commit,
232+
to: target_commit,
233+
});
202234
branch
203235
.get_mut()
204236
.set_target(target_commit, "git-instafix retarget historical branch")?;
205237
}
206238
}
207239
}
208-
Ok(())
240+
Ok(retargeted)
209241
}
210242
}
211243

0 commit comments

Comments
 (0)