@@ -19,7 +19,8 @@ import (
1919
2020 "github.com/git-time-metric/gtm/scm"
2121 "github.com/git-time-metric/gtm/util"
22- isatty "github.com/mattn/go-isatty"
22+ "github.com/git-time-metric/gtm/gtmdebug"
23+ "github.com/mattn/go-isatty"
2324)
2425
2526var (
@@ -83,23 +84,31 @@ The following items have been removed.
8384// Initialize initializes a git repo for time tracking
8485func Initialize (terminal bool , tags []string , clearTags bool ) (string , error ) {
8586 wd , err := os .Getwd ()
87+ gtmdebug .Debugf ("[command/project.go] wd=%s" , wd )
88+
8689 if err != nil {
8790 return "" , err
8891 }
8992
90- projRoot , err := scm .RootPath (wd )
93+ gitRepoPath , err := scm .GitRepoPath (wd )
94+ gtmdebug .Debugf ("[command/project.go::Initialize] gitRepoPath=%s" , gitRepoPath )
9195 if err != nil {
9296 return "" , fmt .Errorf (
93- "Unable to intialize Git Time Metric, Git repository not found in %s" , projRoot )
97+ "Unable to intialize Git Time Metric, Git repository not found in '%s'" , gitRepoPath )
98+ }
99+ if _ , err := os .Stat (gitRepoPath ); os .IsNotExist (err ) {
100+ return "" , fmt .Errorf (
101+ "Unable to intialize Git Time Metric, Git repository not found in %s" , gitRepoPath )
94102 }
95103
96- gitPath := filepath .Join (projRoot , ".git" )
97- if _ , err := os .Stat (gitPath ); os .IsNotExist (err ) {
104+ workDirRoot , err := scm .Workdir (gitRepoPath )
105+ gtmdebug .Debugf ("[command/project.go::Initialize] workDirRoot=%s" , workDirRoot )
106+ if _ , err := os .Stat (workDirRoot ); os .IsNotExist (err ) {
98107 return "" , fmt .Errorf (
99- "Unable to intialize Git Time Metric, Git repository not found in %s" , gitPath )
108+ "Unable to intialize Git Time Metric, Git working tree root not found in %s" , workDirRoot )
100109 }
101110
102- gtmPath := filepath .Join (projRoot , GTMDir )
111+ gtmPath := filepath .Join (workDirRoot , GTMDir )
103112 if _ , err := os .Stat (gtmPath ); os .IsNotExist (err ) {
104113 if err := os .MkdirAll (gtmPath , 0700 ); err != nil {
105114 return "" , err
@@ -130,15 +139,15 @@ func Initialize(terminal bool, tags []string, clearTags bool) (string, error) {
130139 os .Remove (filepath .Join (gtmPath , "terminal.app" ))
131140 }
132141
133- if err := scm .SetHooks (GitHooks , projRoot ); err != nil {
142+ if err := scm .SetHooks (GitHooks , gitRepoPath ); err != nil {
134143 return "" , err
135144 }
136145
137- if err := scm .ConfigSet (GitConfig , projRoot ); err != nil {
146+ if err := scm .ConfigSet (GitConfig , gitRepoPath ); err != nil {
138147 return "" , err
139148 }
140149
141- if err := scm .IgnoreSet (GitIgnore , projRoot ); err != nil {
150+ if err := scm .IgnoreSet (GitIgnore , workDirRoot ); err != nil {
142151 return "" , err
143152 }
144153
@@ -161,7 +170,7 @@ func Initialize(terminal bool, tags []string, clearTags bool) (string, error) {
161170 }{
162171 strings .Join (tags , " " ),
163172 headerFormat ,
164- projRoot ,
173+ workDirRoot ,
165174 GitHooks ,
166175 GitConfig ,
167176 GitIgnore ,
@@ -177,7 +186,7 @@ func Initialize(terminal bool, tags []string, clearTags bool) (string, error) {
177186 return "" , err
178187 }
179188
180- index .add (projRoot )
189+ index .add (workDirRoot )
181190 err = index .save ()
182191 if err != nil {
183192 return "" , err
@@ -193,24 +202,25 @@ func Uninitialize() (string, error) {
193202 return "" , err
194203 }
195204
196- projRoot , err := scm .RootPath (wd )
205+ gitRepoPath , err := scm .GitRepoPath (wd )
197206 if err != nil {
198207 return "" , fmt .Errorf (
199- "Unable to unintialize Git Time Metric, Git repository not found in %s" , projRoot )
208+ "Unable to unintialize Git Time Metric, Git repository not found in %s" , gitRepoPath )
200209 }
201210
202- gtmPath := filepath .Join (projRoot , GTMDir )
211+ workDir , _ := scm .Workdir (gitRepoPath )
212+ gtmPath := filepath .Join (workDir , GTMDir )
203213 if _ , err := os .Stat (gtmPath ); os .IsNotExist (err ) {
204214 return "" , fmt .Errorf (
205215 "Unable to uninitialize Git Time Metric, %s directory not found" , gtmPath )
206216 }
207- if err := scm .RemoveHooks (GitHooks , projRoot ); err != nil {
217+ if err := scm .RemoveHooks (GitHooks , gitRepoPath ); err != nil {
208218 return "" , err
209219 }
210- if err := scm .ConfigRemove (GitConfig , projRoot ); err != nil {
220+ if err := scm .ConfigRemove (GitConfig , gitRepoPath ); err != nil {
211221 return "" , err
212222 }
213- if err := scm .IgnoreRemove (GitIgnore , projRoot ); err != nil {
223+ if err := scm .IgnoreRemove (GitIgnore , workDir ); err != nil {
214224 return "" , err
215225 }
216226 if err := os .RemoveAll (gtmPath ); err != nil {
@@ -232,7 +242,7 @@ func Uninitialize() (string, error) {
232242 GitIgnore string
233243 }{
234244 headerFormat ,
235- projRoot ,
245+ workDir ,
236246 GitHooks ,
237247 GitConfig ,
238248 GitIgnore })
@@ -246,7 +256,7 @@ func Uninitialize() (string, error) {
246256 return "" , err
247257 }
248258
249- index .remove (projRoot )
259+ index .remove (workDir )
250260 err = index .save ()
251261 if err != nil {
252262 return "" , err
@@ -262,11 +272,13 @@ func Clean(dr util.DateRange, terminalOnly bool) error {
262272 return err
263273 }
264274
265- projRoot , err := scm .RootPath (wd )
275+ gitRepoPath , err := scm .GitRepoPath (wd )
266276 if err != nil {
267- return fmt .Errorf ("Unable to clean, Git repository not found in %s" , projRoot )
277+ return fmt .Errorf ("Unable to clean, Git repository not found in %s" , gitRepoPath )
268278 }
269279
280+ projRoot , _ := scm .Workdir (gitRepoPath )
281+
270282 gtmPath := filepath .Join (projRoot , GTMDir )
271283 if _ , err := os .Stat (gtmPath ); os .IsNotExist (err ) {
272284 return fmt .Errorf ("Unable to clean GTM data, %s directory not found" , gtmPath )
@@ -310,17 +322,18 @@ func Paths(wd ...string) (string, string, error) {
310322 util .TimeTrack (time .Now (), "project.Paths" )
311323
312324 var (
313- repoPath string
325+ gitRepoPath string
314326 err error
315327 )
316328 if len (wd ) > 0 {
317- repoPath , err = scm .RootPath (wd [0 ])
329+ gitRepoPath , err = scm .GitRepoPath (wd [0 ])
318330 } else {
319- repoPath , err = scm .RootPath ()
331+ gitRepoPath , err = scm .GitRepoPath ()
320332 }
321333 if err != nil {
322334 return "" , "" , ErrNotInitialized
323335 }
336+ repoPath , _ := scm .Workdir (gitRepoPath )
324337
325338 gtmPath := filepath .Join (repoPath , GTMDir )
326339 if _ , err := os .Stat (gtmPath ); os .IsNotExist (err ) {
0 commit comments