Skip to content

Commit 138e20f

Browse files
committed
feat: click the sync state to sync, and state-aware clickable key hints
The header leads with the repo and branch, and shows the upstream only when it isn't origin/<branch>. The commit box gets padding and a blank row on each side in place of the rule above the hints.
1 parent 284ba12 commit 138e20f

3 files changed

Lines changed: 208 additions & 67 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ key.
5454
| `c` | Write the commit message (drafted for you when something is staged) |
5555
| `Tab` | Draft a commit message with Claude |
5656
| `g` | Show the commit graph |
57+
| Click `✓ synced`, `↑2 to push`… | Sync: publish the branch, or fetch, pull `--ff-only` and push |
5758
| `p` / `P` / `f` | Push / pull `--ff-only` / fetch (it also fetches every 3 minutes) |
5859
| `t` | Stage the files from the agents' latest turn (with Axel) |
5960
| `q` | Quit |
@@ -65,6 +66,8 @@ asks Claude to draft the message, or to finish the one you started, keeping your
6566
staged, `Enter` asks first: `Enter` again stages everything and commits, `s` goes back
6667
to pick files.
6768

69+
The bottom line shows the keys that fit what you're doing, and clicking one presses it.
70+
6871
The commit graph shows the current branch, and `a` switches to every branch and tag. `Esc` or
6972
`g` goes back.
7073

‎src/git.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,31 @@ pub fn diff_text(dir: &Path, e: &Entry, context: u32) -> String {
209209
/// Ask Claude for a commit message for the staged changes, or for all
210210
/// changes when nothing is staged. `start` is what the user has typed so far,
211211
/// to complete; `intent` is the Axel thread's goal, for the why.
212+
/// Bring the branch level with its upstream: publish it if it has none,
213+
/// otherwise fetch, pull (fast-forward only) what's new, and push what's ours.
214+
pub fn sync(dir: &Path) -> Result<String, String> {
215+
if git(dir, &["rev-parse", "--abbrev-ref", "@{u}"]).is_err() {
216+
git(dir, &["push", "--quiet", "-u", "origin", "HEAD"])?;
217+
return Ok("published".into());
218+
}
219+
git(dir, &["fetch", "--quiet", "--prune"])?;
220+
let count = |range: &str| {
221+
git(dir, &["rev-list", "--count", range]).ok().and_then(|s| s.trim().parse::<u32>().ok()).unwrap_or(0)
222+
};
223+
let (behind, ahead) = (count("HEAD..@{u}"), count("@{u}..HEAD"));
224+
let commits = |n: u32| if n == 1 { "1 commit".to_string() } else { format!("{n} commits") };
225+
let mut done = Vec::new();
226+
if behind > 0 {
227+
git(dir, &["pull", "--ff-only", "--quiet"])?;
228+
done.push(format!("pulled {}", commits(behind)));
229+
}
230+
if ahead > 0 {
231+
git(dir, &["push", "--quiet"])?;
232+
done.push(format!("pushed {}", commits(ahead)));
233+
}
234+
Ok(if done.is_empty() { "up to date".into() } else { done.join(", ") })
235+
}
236+
212237
/// One row of `git log --graph`: the lane drawing, and the commit if the row
213238
/// has one (rows that only bend lanes don't).
214239
pub struct GraphRow {

0 commit comments

Comments
 (0)