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>
This commit is contained in:
@@ -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,13 @@ 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";
|
||||
}
|
||||
|
||||
@PostMapping("/repo/{name}/delete")
|
||||
public String delete(@PathVariable String name) throws IOException
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user