@@ -3,37 +3,40 @@ package doctor
33import (
44 "os"
55 "path/filepath"
6- "strings"
76
87 "git-genius/internal/config"
98 "git-genius/internal/github"
109 "git-genius/internal/system"
1110 "git-genius/internal/ui"
1211)
1312
14- // Run performs full system + git health check (ANDROID SAFE)
13+ /*
14+ Doctor:
15+ Full system + git + github health check
16+ No offline mode
17+ Compatible with new system layer
18+ Android safe
19+ */
1520func Run () {
16- ui .Header ("Git Genius Doctor 🩺" )
1721
18- system . CheckInternet ( )
22+ ui . Header ( "Git Genius Doctor 🩺" )
1923
2024 checkGitInstalled ()
2125 checkWorkDir ()
2226 checkGitRepo ()
2327 checkGitBranch ()
2428 checkGitIdentity ()
2529 checkRemote ()
26- checkInternet ()
2730 checkGitHubToken ()
2831 checkGitHubRepo ()
2932 checkErrorLog ()
3033
3134 ui .Success ("Doctor check completed" )
3235}
3336
34- /* ============================================================
35- CHECKS
36- ============================================================ * /
37+ ///////////////////////////////////////////////////////////////
38+ // CHECKS
39+ ////////////////////////////////////////////////////////////// /
3740
3841func checkGitInstalled () {
3942 if system .CommandExists ("git" ) {
@@ -42,7 +45,6 @@ func checkGitInstalled() {
4245 }
4346
4447 ui .Error ("Git not found in PATH" )
45- ui .Info ("Please install git manually for your environment" )
4648}
4749
4850func checkWorkDir () {
@@ -69,47 +71,34 @@ func checkGitRepo() {
6971 }
7072
7173 ui .Warn ("No git repository found" )
72-
73- if ui .Confirm ("Initialize git repository here?" ) {
74- if err := system .RunGitAt (dir , "init" ); err != nil {
75- ui .Error ("Failed to initialize git repository" )
76- return
77- }
78- system .EnsureSafeDirectory (dir )
79- ui .Success ("Git repository initialized" )
80- }
74+ ui .Info ("Run Setup to initialize repository" )
8175}
8276
8377func checkGitBranch () {
8478 cfg := config .Load ()
8579 dir := cfg .GetWorkDir ()
8680
87- current := system .CurrentGitBranchAt (dir )
88-
89- if current == "" {
81+ branch , err := system .GitOutputAt (dir , "branch" , "--show-current" )
82+ if err != nil || branch == "" {
9083 ui .Warn ("No commits yet (branch not created)" )
9184 return
9285 }
9386
94- ui .Success ("Current git branch: " + current )
87+ ui .Success ("Current git branch: " + branch )
9588
96- if current != cfg .Branch {
89+ if branch != cfg .Branch {
9790 ui .Warn ("Branch mismatch detected" )
9891 ui .Info ("Config branch : " + cfg .Branch )
99- ui .Info ("Git branch : " + current )
100- ui .Info ("Run Setup to safely sync branch" )
92+ ui .Info ("Git branch : " + branch )
10193 }
10294}
10395
104- /*
105- Git identity check (ANDROID SAFE, LOCAL REPO ONLY)
106- */
10796func checkGitIdentity () {
10897 cfg := config .Load ()
10998 dir := cfg .GetWorkDir ()
11099
111- name := gitConfig (dir , "user.name" )
112- email := gitConfig (dir , "user.email" )
100+ name , _ := system . GitOutputAt (dir , "config" , "--get" , "user.name" )
101+ email , _ := system . GitOutputAt (dir , "config" , "--get" , "user.email" )
113102
114103 if name != "" && email != "" {
115104 ui .Success ("Git identity configured" )
@@ -119,27 +108,7 @@ func checkGitIdentity() {
119108 }
120109
121110 ui .Warn ("Git identity not configured" )
122- ui .Info ("Commits may appear as root@localhost" )
123-
124- if ! ui .Confirm ("Configure git identity for THIS repo now?" ) {
125- return
126- }
127-
128- if name == "" {
129- val := ui .Input ("Enter your name" )
130- if val != "" {
131- _ = system .RunGitAt (dir , "config" , "user.name" , val )
132- }
133- }
134-
135- if email == "" {
136- val := ui .Input ("Enter your email" )
137- if val != "" {
138- _ = system .RunGitAt (dir , "config" , "user.email" , val )
139- }
140- }
141-
142- ui .Success ("Git identity configured (local repository)" )
111+ ui .Info ("Run Setup to configure git identity" )
143112}
144113
145114func checkRemote () {
@@ -151,41 +120,33 @@ func checkRemote() {
151120 return
152121 }
153122
154- if err := system .RunGitAt (dir , "remote" , "get-url" , cfg .Remote ); err != nil {
123+ _ , err := system .GitOutputAt (dir , "remote" , "get-url" , cfg .Remote )
124+ if err != nil {
155125 ui .Warn ("Remote not found: " + cfg .Remote )
156- ui .Info ("Run Tools → Create / Link GitHub Repository" )
126+ ui .Info ("Run Create / Link GitHub Repository" )
157127 return
158128 }
159129
160130 ui .Success ("Git remote configured: " + cfg .Remote )
161131}
162132
163- func checkInternet () {
164- if system .Online {
165- ui .Success ("Internet connection available" )
166- } else {
167- ui .Warn ("Offline mode detected" )
168- ui .Info ("GitHub validation & push may fail" )
169- }
170- }
171-
172133func checkGitHubToken () {
134+
173135 token := github .GetToken ()
174136 if token == "" {
175137 ui .Warn ("GitHub token not configured" )
176- ui .Info ("Run Setup to configure token" )
177138 return
178139 }
179140
180- user , err := github .Validate ()
141+ client , err := github .NewClient ()
181142 if err != nil {
182- ui .Error ("GitHub token invalid or expired" )
183- ui .Info ("Run Setup to reconfigure token" )
143+ ui .Error ("Invalid GitHub token" )
184144 return
185145 }
186146
187- if user == "offline-mode" {
188- ui .Warn ("GitHub token validation skipped (offline)" )
147+ user , err := client .GetAuthenticatedUser ()
148+ if err != nil {
149+ ui .Warn ("GitHub token invalid or expired" )
189150 return
190151 }
191152
@@ -209,13 +170,18 @@ func checkGitHubRepo() {
209170 ui .Success ("GitHub repository exists" )
210171 } else {
211172 ui .Warn ("GitHub repository does not exist" )
212- ui .Info ("Run Tools → Create / Link GitHub Repository" )
213173 }
214174}
215175
216176func checkErrorLog () {
217177 cfg := config .Load ()
218- logPath := filepath .Join (cfg .GetWorkDir (), ".git" , ".genius" , "error.log" )
178+
179+ logPath := filepath .Join (
180+ cfg .GetWorkDir (),
181+ ".git" ,
182+ ".genius" ,
183+ "error.log" ,
184+ )
219185
220186 if _ , err := os .Stat (logPath ); err == nil {
221187 ui .Warn ("Error log exists" )
@@ -224,18 +190,3 @@ func checkErrorLog() {
224190 ui .Success ("No error log found" )
225191 }
226192}
227-
228- /* ============================================================
229- HELPERS
230- ============================================================ */
231-
232- func gitConfig (dir , key string ) string {
233- var out strings.Builder
234- cmd := system .GitCmdAt (dir , "config" , "--get" , key )
235- cmd .Stdout = & out
236-
237- if err := cmd .Run (); err != nil {
238- return ""
239- }
240- return strings .TrimSpace (out .String ())
241- }
0 commit comments