Compare commits

...

4 Commits

Author SHA1 Message Date
383864469d Add delete confirmation page before removing repository
The Delete Repository button now navigates to a confirmation page
asking 'Are you sure?' with Yes/No options. Only the Yes button
performs the actual delete POST. No JavaScript required.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-27 09:31:03 +01:00
4458eb204b Show remotes in table with editable URLs on remote page
List all configured remotes in a table with name, editable URL
field with Save button, and per-remote Push/Pull buttons.
Add GitService.listRemotes() and updateRemoteUrl() methods.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-27 09:28:43 +01:00
005e0c7d23 Make staging (changes) the default repo view
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-27 09:23:59 +01:00
be130582fc Reorder sidebar: Staging above Branches, rename Changes to Staging
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-27 09:21:34 +01:00
9 changed files with 150 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ public class RepoController
@GetMapping("/repo/{name}")
public String repo(@PathVariable String name)
{
return "redirect:/repo/" + name + "/branches";
return "redirect:/repo/" + name + "/changes";
}
@GetMapping("/repo/{name}/branches")
@@ -44,9 +44,10 @@ public class RepoController
}
@GetMapping("/repo/{name}/remote")
public String remote(@PathVariable String name, Model model)
public String remote(@PathVariable String name, Model model) throws IOException
{
model.addAttribute("name", name);
model.addAttribute("remotes", gitService.listRemotes(name));
return "remote";
}
@@ -106,6 +107,20 @@ public class RepoController
return "redirect:/repo/" + name + "/remote";
}
@PostMapping("/repo/{name}/update-remote")
public String updateRemote(@PathVariable String name, @RequestParam String remote, @RequestParam String url) throws IOException
{
gitService.updateRemoteUrl(name, remote, url);
return "redirect:/repo/" + name + "/remote";
}
@GetMapping("/repo/{name}/confirm-delete")
public String confirmDelete(@PathVariable String name, Model model)
{
model.addAttribute("name", name);
return "confirm-delete";
}
@PostMapping("/repo/{name}/delete")
public String delete(@PathVariable String name) throws IOException
{

View File

@@ -13,7 +13,9 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@Service
@@ -216,6 +218,32 @@ public class GitService
}
}
public Map<String, String> listRemotes(String name) throws IOException
{
try (Git git = openRepository(name))
{
StoredConfig config = git.getRepository().getConfig();
var remoteNames = config.getSubsections("remote");
Map<String, String> remotes = new LinkedHashMap<>();
for (String remote : remoteNames)
{
String url = config.getString("remote", remote, "url");
remotes.put(remote, url != null ? url : "");
}
return remotes;
}
}
public void updateRemoteUrl(String name, String remote, String url) throws IOException
{
try (Git git = openRepository(name))
{
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", remote, "url", url);
config.save();
}
}
public void push(String name) throws IOException, GitAPIException
{
try (Git git = openRepository(name))

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="'Confirm Delete - ' + ${name}">Confirm Delete</title>
</head>
<body>
<h2>Are you sure?</h2>
<p>This will permanently delete the repository <b th:text="${name}"></b> and its working tree.</p>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
<form method="post" th:action="@{/repo/{name}/delete(name=${name})}" target="_top">
<input type="submit" value="Yes">
</form>
</td>
<td>
<a th:href="@{/repo/{name}/manage(name=${name})}">No</a>
</td>
</tr>
</table>
</body>
</html>

View File

@@ -4,7 +4,7 @@
</head>
<frameset cols="180,*">
<frame th:src="${selectedRepo != null} ? '/nav?repo=' + ${selectedRepo} : '/nav'" name="nav">
<frame th:src="${showCloneForm} ? '/clone-form' : (${selectedRepo != null} ? '/repo/' + ${selectedRepo} + '/branches' : '/welcome')" name="content">
<frame th:src="${showCloneForm} ? '/clone-form' : (${selectedRepo != null} ? '/repo/' + ${selectedRepo} + '/changes' : '/welcome')" name="content">
<noframes>
<body>
<p>Your browser does not support frames. <a href="/repos">Click here</a> to continue.</p>

View File

@@ -8,7 +8,7 @@
<h3>Danger Zone</h3>
<p>This will permanently delete the repository and its working tree.</p>
<form method="post" th:action="@{/repo/{name}/delete(name=${name})}" target="_top">
<form method="get" th:action="@{/repo/{name}/confirm-delete(name=${name})}">
<input type="submit" value="Delete Repository">
</form>

View File

@@ -19,8 +19,8 @@
<th:block th:if="${selectedRepo != null}">
<hr>
<b th:text="${selectedRepo}"></b><br>
<a th:href="@{/repo/{name}/changes(name=${selectedRepo})}" target="content">Staging</a><br>
<a th:href="@{/repo/{name}/branches(name=${selectedRepo})}" target="content">Branches</a><br>
<a th:href="@{/repo/{name}/changes(name=${selectedRepo})}" target="content">Changes</a><br>
<a th:href="@{/repo/{name}/remote(name=${selectedRepo})}" target="content">Remote</a><br>
<a th:href="@{/repo/{name}/manage(name=${selectedRepo})}" target="content">Manage</a><br>
</th:block>

View File

@@ -4,10 +4,24 @@
<title th:text="'Remote - ' + ${name}">Remote</title>
</head>
<body>
<h2>Remote</h2>
<h2>Remotes</h2>
<table border="0" cellpadding="4" cellspacing="0">
<table border="1" cellpadding="4" cellspacing="0">
<tr>
<th>Name</th>
<th>URL</th>
<th></th>
<th></th>
</tr>
<tr th:each="entry : ${remotes}">
<td th:text="${entry.key}"></td>
<td>
<form method="post" th:action="@{/repo/{name}/update-remote(name=${name})}">
<input type="hidden" name="remote" th:value="${entry.key}">
<input type="text" name="url" th:value="${entry.value}" size="40">
<input type="submit" value="Save">
</form>
</td>
<td>
<form method="post" th:action="@{/repo/{name}/push(name=${name})}">
<input type="submit" value="Push">
@@ -21,5 +35,7 @@
</tr>
</table>
<p th:if="${remotes.isEmpty()}">No remotes configured.</p>
</body>
</html>

View File

@@ -25,11 +25,11 @@ class RepoControllerTest
private GitService gitService;
@Test
void repoRedirectsToBranches() throws Exception
void repoRedirectsToChanges() throws Exception
{
mockMvc.perform(get("/repo/myrepo"))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/repo/myrepo/branches"));
.andExpect(redirectedUrl("/repo/myrepo/changes"));
}
@Test
@@ -74,12 +74,26 @@ class RepoControllerTest
}
@Test
void remotePageLoads() throws Exception
void remotePageShowsRemotes() throws Exception
{
when(gitService.listRemotes("myrepo")).thenReturn(java.util.Map.of("origin", "https://example.com/repo.git"));
mockMvc.perform(get("/repo/myrepo/remote"))
.andExpect(status().isOk())
.andExpect(view().name("remote"))
.andExpect(model().attribute("name", "myrepo"));
.andExpect(model().attribute("name", "myrepo"))
.andExpect(content().string(org.hamcrest.Matchers.containsString("origin")))
.andExpect(content().string(org.hamcrest.Matchers.containsString("https://example.com/repo.git")));
}
@Test
void remotePageShowsNoRemotes() throws Exception
{
when(gitService.listRemotes("myrepo")).thenReturn(java.util.Map.of());
mockMvc.perform(get("/repo/myrepo/remote"))
.andExpect(status().isOk())
.andExpect(content().string(org.hamcrest.Matchers.containsString("No remotes configured.")));
}
@Test
@@ -168,6 +182,28 @@ class RepoControllerTest
verify(gitService).pull("myrepo");
}
@Test
void updateRemoteRedirectsToRemote() throws Exception
{
mockMvc.perform(post("/repo/myrepo/update-remote")
.param("remote", "origin")
.param("url", "https://new-url.com/repo.git"))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/repo/myrepo/remote"));
verify(gitService).updateRemoteUrl("myrepo", "origin", "https://new-url.com/repo.git");
}
@Test
void confirmDeleteShowsConfirmation() throws Exception
{
mockMvc.perform(get("/repo/myrepo/confirm-delete"))
.andExpect(status().isOk())
.andExpect(view().name("confirm-delete"))
.andExpect(model().attribute("name", "myrepo"))
.andExpect(content().string(org.hamcrest.Matchers.containsString("Are you sure?")));
}
@Test
void deleteRedirectsToRoot() throws Exception
{

View File

@@ -311,4 +311,26 @@ class GitServiceTest
{
assertThrows(IllegalArgumentException.class, () -> gitService.cloneRepository(".git", null));
}
@Test
void listRemotesReturnsConfiguredRemotes() throws GitAPIException, IOException
{
gitService.cloneRepository(bareRemote.toUri().toString(), "myrepo");
var remotes = gitService.listRemotes("myrepo");
assertEquals(1, remotes.size());
assertTrue(remotes.containsKey("origin"));
assertEquals(bareRemote.toUri().toString(), remotes.get("origin"));
}
@Test
void updateRemoteUrlChangesUrl() throws GitAPIException, IOException
{
gitService.cloneRepository(bareRemote.toUri().toString(), "myrepo");
gitService.updateRemoteUrl("myrepo", "origin", "https://new-url.com/repo.git");
var remotes = gitService.listRemotes("myrepo");
assertEquals("https://new-url.com/repo.git", remotes.get("origin"));
}
}