From 52fe455c7685826d2971da089da6c806071f031c Mon Sep 17 00:00:00 2001
From: Sebastiaan de Schaetzen
Date: Fri, 27 Feb 2026 19:22:03 +0100
Subject: [PATCH] Add ahead/behind indicator and push/pull buttons
---
.../webgit/config/WebgitProperties.java | 2 ++
.../webgit/controller/RepoController.java | 16 ++++++++++++----
.../be/seeseepuff/webgit/service/GitService.java | 13 +++++++++++++
src/main/resources/templates/changes.html | 11 +++++++++++
4 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/src/main/java/be/seeseepuff/webgit/config/WebgitProperties.java b/src/main/java/be/seeseepuff/webgit/config/WebgitProperties.java
index 74ee9d1..040615b 100644
--- a/src/main/java/be/seeseepuff/webgit/config/WebgitProperties.java
+++ b/src/main/java/be/seeseepuff/webgit/config/WebgitProperties.java
@@ -16,4 +16,6 @@ public class WebgitProperties
private Path worktreePath;
private Path gitDirPath;
private Integer telnetPort;
+ private String username;
+ private String password;
}
diff --git a/src/main/java/be/seeseepuff/webgit/controller/RepoController.java b/src/main/java/be/seeseepuff/webgit/controller/RepoController.java
index 649fbf5..ff273fa 100644
--- a/src/main/java/be/seeseepuff/webgit/controller/RepoController.java
+++ b/src/main/java/be/seeseepuff/webgit/controller/RepoController.java
@@ -57,6 +57,12 @@ public class RepoController
model.addAttribute("branch", gitService.getCurrentBranch(name));
model.addAttribute("modifiedFiles", gitService.getModifiedFiles(name));
model.addAttribute("stagedFiles", gitService.getStagedFiles(name));
+ int[] aheadBehind = gitService.getAheadBehind(name);
+ if (aheadBehind != null)
+ {
+ model.addAttribute("commitsAhead", aheadBehind[0]);
+ model.addAttribute("commitsBehind", aheadBehind[1]);
+ }
return "changes";
}
@@ -224,17 +230,19 @@ public class RepoController
}
@PostMapping("/repo/{name}/push")
- public String push(@PathVariable String name) throws IOException, GitAPIException
+ public String push(@PathVariable String name,
+ @RequestParam(required = false, defaultValue = "remote") String redirectTo) throws IOException, GitAPIException
{
gitService.push(name);
- return "redirect:/repo/" + name + "/remote";
+ return "redirect:/repo/" + name + "/" + redirectTo;
}
@PostMapping("/repo/{name}/pull")
- public String pull(@PathVariable String name) throws IOException, GitAPIException
+ public String pull(@PathVariable String name,
+ @RequestParam(required = false, defaultValue = "remote") String redirectTo) throws IOException, GitAPIException
{
gitService.pull(name);
- return "redirect:/repo/" + name + "/remote";
+ return "redirect:/repo/" + name + "/" + redirectTo;
}
@PostMapping("/repo/{name}/update-remote")
diff --git a/src/main/java/be/seeseepuff/webgit/service/GitService.java b/src/main/java/be/seeseepuff/webgit/service/GitService.java
index b1f14fe..d76a32a 100644
--- a/src/main/java/be/seeseepuff/webgit/service/GitService.java
+++ b/src/main/java/be/seeseepuff/webgit/service/GitService.java
@@ -598,6 +598,19 @@ public class GitService
}
}
+ public int[] getAheadBehind(String name) throws IOException
+ {
+ try (Git git = openRepository(name))
+ {
+ String branch = git.getRepository().getBranch();
+ org.eclipse.jgit.lib.BranchTrackingStatus status =
+ org.eclipse.jgit.lib.BranchTrackingStatus.of(git.getRepository(), branch);
+ if (status == null)
+ return null;
+ return new int[]{status.getAheadCount(), status.getBehindCount()};
+ }
+ }
+
public void push(String name) throws IOException, GitAPIException
{
try (Git git = openRepository(name))
diff --git a/src/main/resources/templates/changes.html b/src/main/resources/templates/changes.html
index dca1e95..e1e4a71 100644
--- a/src/main/resources/templates/changes.html
+++ b/src/main/resources/templates/changes.html
@@ -6,6 +6,17 @@
Staging
Branch:
+
+ ahead, behind
+
+
+
Modified Files (unstaged)