Skip to content

Commit dc7424d

Browse files
committed
updating wiring
1 parent 782b51f commit dc7424d

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

git-genius

1.5 KB
Binary file not shown.

internal/setup/change_dir.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func ChangeProjectDir() {
1818
ui.Header("Change Project Directory")
1919

2020
cfg := config.Load()
21+
origCwd, _ := os.Getwd()
2122

2223
// Show current directory
2324
current := cfg.GetWorkDir()
@@ -45,6 +46,11 @@ func ChangeProjectDir() {
4546

4647
// Save new workdir
4748
cfg.WorkDir = abs
49+
// Keep config + error logs synchronized with the chosen workdir.
50+
if cfg.WorkDir != "" {
51+
_ = os.Chdir(cfg.WorkDir)
52+
defer func() { _ = os.Chdir(origCwd) }()
53+
}
4854
config.Save(cfg)
4955

5056
ui.Success("Project directory updated")

internal/setup/setup.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func Run() {
5353
ui.Header("Git Genius Setup")
5454

5555
cfg := config.Load()
56+
origCwd, _ := os.Getwd()
5657
// #region agent log
5758
debugLog("pre-fix", "H1", "internal/setup/setup.go:Run", "setup started", map[string]interface{}{
5859
"initialWorkDir": cfg.WorkDir,
@@ -68,6 +69,12 @@ func Run() {
6869
// #endregion
6970
return
7071
}
72+
// Keep config + error logs synchronized with the chosen workdir.
73+
// These codepaths use relative paths like ".git/.genius".
74+
if cfg.WorkDir != "" {
75+
_ = os.Chdir(cfg.WorkDir)
76+
defer func() { _ = os.Chdir(origCwd) }()
77+
}
7178
config.Save(cfg)
7279
// #region agent log
7380
debugLog("pre-fix", "H1", "internal/setup/setup.go:Run", "workdir saved", map[string]interface{}{
@@ -295,16 +302,24 @@ func setupGitHubToken() bool {
295302
///////////////////////////////////////////////////////////////
296303

297304
func ensureGitHubRepo(cfg *config.Config) {
305+
// Best-effort existence check to avoid noisy 422 errors.
306+
exists, err := github.RepoExists(cfg.Owner, cfg.Repo)
307+
if err == nil && exists {
308+
ui.Success("GitHub repository already exists")
309+
return
310+
}
311+
312+
// If verification failed, fall back to user-driven create flow.
298313
if !ui.Confirm("Create repository on GitHub if not exists?") {
299314
return
300315
}
301316

302317
private := ui.Confirm("Make repository PRIVATE?")
303318

304-
err := github.CreateRepo(cfg.Owner, cfg.Repo, private)
305-
if err != nil {
319+
createErr := github.CreateRepo(cfg.Owner, cfg.Repo, private)
320+
if createErr != nil {
306321
ui.Warn("Repository creation failed:")
307-
ui.Info(err.Error())
322+
ui.Info(createErr.Error())
308323
return
309324
}
310325

@@ -357,8 +372,23 @@ func offerFirstPush(cfg *config.Config) {
357372
return
358373
}
359374

360-
// Commit may fail if nothing to commit
361-
_ = system.RunGit("commit", "-m", msg)
375+
// Avoid pushing without a real first commit.
376+
// Common case: empty repo => "nothing to commit" after `git add .`.
377+
stagedNames, err := system.GitOutput("diff", "--cached", "--name-only")
378+
if err != nil {
379+
ui.Error("Failed to check staged changes")
380+
return
381+
}
382+
if stagedNames == "" {
383+
ui.Warn("Nothing to commit yet (working tree is empty)")
384+
ui.Info("Add at least one file, then push again.")
385+
return
386+
}
387+
388+
if err := system.RunGit("commit", "-m", msg); err != nil {
389+
ui.Error("Initial commit failed")
390+
return
391+
}
362392

363393
branch := system.CurrentGitBranch()
364394
if branch == "" {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Build:
119119

120120
```bash
121121
go fmt ./...
122-
go build -o git-genius ./cmd/genius
122+
CGO_ENABLED=0 go build -o git-genius ./cmd/genius
123123
./git-genius
124124
```
125125

0 commit comments

Comments
 (0)