feat(client): lodge remote binds a repository to another server

This commit is contained in:
hh committed 2026-10-02 22:05:10 +00:00
1 parent 45c81cfcaf
commit 91d83f3032
10 files changed
+639 -147

No files matched your search

+15 -11
View File
@@ -75,11 +75,11 @@ func unitPath(home string) string {
return filepath.Join(home, ".config", "systemd", "user", systemdUnit)
}
func (c *Client) templateDir() string {
return filepath.Join(c.DataDir, "git-template")
func (cfg *Config) templateDir() string {
return filepath.Join(cfg.DataDir, "git-template")
}
func (c *Client) Install() error {
func (cfg *Config) Install() error {
binary, err := os.Executable()
if err != nil {
return err
@@ -88,7 +88,7 @@ func (c *Client) Install() error {
if err != nil {
return err
}
if err := c.installHook(binary); err != nil {
if err := cfg.installHook(binary); err != nil {
return err
}
for _, dir := range skillDirs {
@@ -96,14 +96,14 @@ func (c *Client) Install() error {
return err
}
}
return startService(home, binary, filepath.Join(c.DataDir, "daemon.log"))
return startService(home, binary, filepath.Join(cfg.DataDir, "daemon.log"))
}
func (c *Client) installHook(binary string) error {
func (cfg *Config) installHook(binary string) error {
template, _ := exec.Command("git", "config", "--global", "--get", "init.templateDir").Output()
dir := strings.TrimSpace(string(template))
if dir == "" {
dir = c.templateDir()
dir = cfg.templateDir()
if err := command("git", "config", "--global", "init.templateDir", dir); err != nil {
return err
}
@@ -146,7 +146,7 @@ func restartService() error {
return command("systemctl", "--user", "restart", systemdUnit)
}
func (c *Client) Uninstall() error {
func (cfg *Config) Uninstall() error {
home, err := os.UserHomeDir()
if err != nil {
return err
@@ -159,16 +159,20 @@ func (c *Client) Uninstall() error {
_ = os.Remove(unitPath(home))
}
template, _ := exec.Command("git", "config", "--global", "--get", "init.templateDir").Output()
if strings.TrimSpace(string(template)) == c.templateDir() {
if strings.TrimSpace(string(template)) == cfg.templateDir() {
_ = command("git", "config", "--global", "--unset", "init.templateDir")
}
for _, dir := range skillDirs {
_ = os.RemoveAll(filepath.Join(home, dir))
}
return os.RemoveAll(c.templateDir())
return os.RemoveAll(cfg.templateDir())
}
func (c *Client) Update(ctx context.Context) (bool, error) {
func (cfg *Config) Update(ctx context.Context) (bool, error) {
c, err := cfg.client(cfg.URL)
if err != nil {
return false, err
}
binary, err := os.Executable()
if err != nil {
return false, err