Skip to content

Commit d6e8083

Browse files
authored
Merge pull request #1008 from wakatime/develop
Release v1.88.1
2 parents c5f84f4 + 4d1fa09 commit d6e8083

File tree

16 files changed

+129
-46
lines changed

16 files changed

+129
-46
lines changed

TROUBLESHOOTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Each plugin also has its own log file:
2020
* **Emacs** messages go to the *messages* buffer window
2121
* **Jetbrains IDEs (IntelliJ IDEA, PyCharm, RubyMine, PhpStorm, AppCode, AndroidStudio, WebStorm)** log to `idea.log` ([locating IDE log files][locating IDE log files])
2222
* **Komodo** logs are written to `pystderr.log` (Help -> Troubleshooting -> View Log File)
23-
* **Netbeans** logs to it's own log file (View -> IDE Log)
23+
* **Netbeans** logs to its own log file (View -> IDE Log)
2424
* **Notepad++** errors go to `AppData\Roaming\Notepad++\plugins\config\WakaTime.log` (this file is only created when an error occurs)
2525
* **Sublime** Text logs to the Sublime Console (View -> Show Console)
2626
* **TextMate** logs to stderr so run TextMate from Terminal to see any errors ([enable logging][textmate logging])
@@ -34,7 +34,7 @@ Check the [Plugin Status Page][plugins status] to see when the API last heard fr
3434
Useful API Endpoints for debugging:
3535

3636
* [List of your Plugins and when they were last heard from][user agents api]
37-
* [List of your Machines and ther IPs][machines api]
37+
* [List of your Machines and their IPs][machines api]
3838

3939
Useful Resources:
4040

USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ projects/foo = your-api-key
133133

134134
### Api Key Environment Variable
135135

136-
If a `WAKATIME_API_KEY` env var exists, wakatime-cli will use it’s value as the api key.
136+
If a `WAKATIME_API_KEY` env var exists, wakatime-cli will use its value as the api key.
137137
This means you don’t need a `~/.wakatime.cfg` file, or you can omit or leave empty the `api_key` setting in your config file if using the env var.
138138
However, if an api key exists in your `~/.wakatime.cfg` file then it takes precedence over the env var.
139139

@@ -157,5 +157,5 @@ For commonly used configuration options, see examples in the [FAQ](https://wakat
157157

158158
## Internal INI Config File
159159

160-
The plugins and waktime-cli use a separate internal INI file for things like caching auto-update requests to the GitHub releases API, and exponential backoff to the WakaTime API.
160+
The plugins and wakatime-cli use a separate internal INI file for things like caching auto-update requests to the GitHub releases API, and exponential backoff to the WakaTime API.
161161
The default internal INI config file location is `$WAKATIME_HOME/.wakatime/wakatime-internal.cfg`.

cmd/today/today.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Run(v *viper.Viper) (int, error) {
3333
return exitcode.Success, nil
3434
}
3535

36-
// Today returns a rendered summary of todays coding activity.
36+
// Today returns a rendered summary of today's coding activity.
3737
func Today(v *viper.Viper) (string, error) {
3838
paramAPI, err := params.LoadAPIParams(v)
3939
if err != nil {

cmd/todaygoal/todaygoal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Run(v *viper.Viper) (int, error) {
4545
return exitcode.Success, nil
4646
}
4747

48-
// Goal returns total time of given goal id for todays coding activity.
48+
// Goal returns total time of given goal id for today's coding activity.
4949
func Goal(v *viper.Viper) (string, error) {
5050
params, err := LoadParams(v)
5151
if err != nil {

go.sum

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
296296
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
297297
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
298298
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
299-
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
300-
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
301299
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
302300
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
303301
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -433,16 +431,13 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
433431
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
434432
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
435433
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
436-
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
437-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
438434
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
439435
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
440436
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
441437
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
442438
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
443-
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
444-
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
445439
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
440+
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
446441
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
447442
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
448443
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -452,8 +447,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
452447
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
453448
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
454449
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
455-
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
456-
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
457450
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
458451
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
459452
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

pkg/apikey/apikey.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ func WithReplacing(config Config) heartbeat.HandleOption {
3434
result, ok := MatchPattern(h.Entity, config.MapPatterns)
3535
if ok {
3636
hh[n].APIKey = result
37-
} else {
38-
hh[n].APIKey = config.DefaultAPIKey
37+
38+
continue
3939
}
40+
41+
hh[n].APIKey = config.DefaultAPIKey
4042
}
4143

4244
return next(hh)

pkg/project/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (f File) Detect() (Result, bool, error) {
4949
return result, true, nil
5050
}
5151

52-
// fileExists checks if a file or directory exist.
53-
func fileExists(fp string) bool {
52+
// fileOrDirExists checks if a file or directory exist.
53+
func fileOrDirExists(fp string) bool {
5454
_, err := os.Stat(fp)
5555
return err == nil || os.IsExist(err)
5656
}

pkg/project/git.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (g Git) Detect() (Result, bool, error) {
2727
fp := g.Filepath
2828

2929
// Take only the directory
30-
if fileExists(fp) {
30+
if fileOrDirExists(fp) {
3131
fp = filepath.Dir(fp)
3232
}
3333

@@ -73,7 +73,9 @@ func (g Git) Detect() (Result, bool, error) {
7373
return Result{}, false, fmt.Errorf("error finding gitdir: %s", err)
7474
}
7575

76-
// Commonly .git file is present when it's a worktree
76+
// Commonly .git folder is present when it's a worktree but there's an exception where
77+
// worktree is present but .git folder is not present. In that case, we need to find
78+
// for worktree folder.
7779
// Find for commondir file
7880
commondir, ok, err := findCommondir(gitdir)
7981
if err != nil {
@@ -82,7 +84,16 @@ func (g Git) Detect() (Result, bool, error) {
8284

8385
// we found a commondir file so this is a worktree
8486
if ok {
85-
project := projectOrRemote(filepath.Base(filepath.Dir(commondir)), g.ProjectFromGitRemote, commondir)
87+
dir := filepath.Dir(commondir)
88+
89+
// Commonly commondir file contains a .git folder but there's an exception where
90+
// commondir contains the actual git folder. It's common when repo is bare and
91+
// it's a worktree.
92+
if strings.LastIndex(commondir, ".git") == -1 {
93+
dir = commondir
94+
}
95+
96+
project := projectOrRemote(filepath.Base(dir), g.ProjectFromGitRemote, commondir)
8697

8798
branch, err := findGitBranch(filepath.Join(gitdir, "HEAD"))
8899
if err != nil {
@@ -96,7 +107,7 @@ func (g Git) Detect() (Result, bool, error) {
96107
return Result{
97108
Project: project,
98109
Branch: branch,
99-
Folder: filepath.Dir(commondir),
110+
Folder: dir,
100111
}, true, nil
101112
}
102113

@@ -198,13 +209,13 @@ func findGitdir(fp string) (string, error) {
198209
return "", nil
199210
}
200211

201-
func resolveGitdir(fp string, gitdir string) (string, error) {
212+
func resolveGitdir(fp, gitdir string) (string, error) {
202213
subPath := strings.TrimSpace(gitdir)
203214
if !filepath.IsAbs(subPath) {
204215
subPath = filepath.Join(fp, subPath)
205216
}
206217

207-
if fileExists(filepath.Join(subPath, "HEAD")) {
218+
if fileOrDirExists(filepath.Join(subPath, "HEAD")) {
208219
return subPath, nil
209220
}
210221

@@ -220,7 +231,7 @@ func findCommondir(fp string) (string, bool, error) {
220231
return "", false, nil
221232
}
222233

223-
if fileExists(filepath.Join(fp, "commondir")) {
234+
if fileOrDirExists(filepath.Join(fp, "commondir")) {
224235
return resolveCommondir(fp)
225236
}
226237

@@ -244,11 +255,7 @@ func resolveCommondir(fp string) (string, bool, error) {
244255
fmt.Errorf("failed to get absolute path: %s", err)
245256
}
246257

247-
if filepath.Base(gitdir) == ".git" {
248-
return gitdir, true, nil
249-
}
250-
251-
return "", false, nil
258+
return gitdir, true, nil
252259
}
253260

254261
func projectOrRemote(projectName string, projectFromGitRemote bool, dotGitFolder string) string {
@@ -273,7 +280,7 @@ func projectOrRemote(projectName string, projectFromGitRemote bool, dotGitFolder
273280
}
274281

275282
func findGitBranch(fp string) (string, error) {
276-
if !fileExists(fp) {
283+
if !fileOrDirExists(fp) {
277284
return "master", nil
278285
}
279286

@@ -290,7 +297,7 @@ func findGitBranch(fp string) (string, error) {
290297
}
291298

292299
func findGitRemote(fp string) (string, error) {
293-
if !fileExists(fp) {
300+
if !fileOrDirExists(fp) {
294301
return "", nil
295302
}
296303

pkg/project/git_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,45 @@ func TestGit_Detect_WorktreeGitRemote(t *testing.T) {
154154
}, result)
155155
}
156156

157+
func TestGit_Detect_Worktree_BareRepo(t *testing.T) {
158+
fp := setupTestGitWorktreeBareRepo(t)
159+
160+
g := project.Git{
161+
Filepath: filepath.Join(fp, "wakatime-cli/master/src/pkg/file.go"),
162+
}
163+
164+
result, detected, err := g.Detect()
165+
require.NoError(t, err)
166+
167+
assert.True(t, detected)
168+
assert.Contains(t, result.Folder, filepath.Join(fp, "wakatime-cli"))
169+
assert.Equal(t, project.Result{
170+
Project: "wakatime-cli",
171+
Branch: "feature/api",
172+
Folder: result.Folder,
173+
}, result)
174+
}
175+
176+
func TestGit_Detect_WorktreeGitRemote_BareRepo(t *testing.T) {
177+
fp := setupTestGitWorktreeBareRepo(t)
178+
179+
g := project.Git{
180+
Filepath: filepath.Join(fp, "wakatime-cli/master/src/pkg/file.go"),
181+
ProjectFromGitRemote: true,
182+
}
183+
184+
result, detected, err := g.Detect()
185+
require.NoError(t, err)
186+
187+
assert.True(t, detected)
188+
assert.Contains(t, result.Folder, filepath.Join(fp, "wakatime-cli"))
189+
assert.Equal(t, project.Result{
190+
Project: "wakatime/wakatime-cli",
191+
Branch: "feature/api",
192+
Folder: result.Folder,
193+
}, result)
194+
}
195+
157196
func TestGit_Detect_Submodule(t *testing.T) {
158197
fp := setupTestGitSubmodule(t)
159198

@@ -456,6 +495,48 @@ func setupTestGitWorktree(t *testing.T) (fp string) {
456495
return tmpDir
457496
}
458497

498+
func setupTestGitWorktreeBareRepo(t *testing.T) (fp string) {
499+
tmpDir := t.TempDir()
500+
501+
tmpDir, err := realpath.Realpath(tmpDir)
502+
require.NoError(t, err)
503+
504+
if runtime.GOOS == "windows" {
505+
tmpDir = windows.FormatFilePath(tmpDir)
506+
}
507+
508+
// Create directories
509+
err = os.MkdirAll(filepath.Join(tmpDir, "wakatime-cli/worktrees/master"), os.FileMode(int(0700)))
510+
require.NoError(t, err)
511+
512+
err = os.MkdirAll(filepath.Join(tmpDir, "wakatime-cli/master/src/pkg"), os.FileMode(int(0700)))
513+
require.NoError(t, err)
514+
515+
// Create fake file
516+
tmpFile, err := os.Create(filepath.Join(tmpDir, "wakatime-cli/master/src/pkg/file.go"))
517+
require.NoError(t, err)
518+
519+
defer tmpFile.Close()
520+
521+
// Setup basic git
522+
copyFile(t, "testdata/git_basic/config", filepath.Join(tmpDir, "wakatime-cli/config"))
523+
copyFile(t, "testdata/git_worktree/HEAD", filepath.Join(tmpDir, "wakatime-cli/HEAD"))
524+
525+
// Setup git worktree
526+
copyFile(t, "testdata/git_worktree/HEAD2", filepath.Join(tmpDir, "wakatime-cli/worktrees/master/HEAD"))
527+
copyFile(t, "testdata/git_worktree/commondir", filepath.Join(tmpDir, "wakatime-cli/worktrees/master/commondir"))
528+
529+
tmpFile, err = os.Create(filepath.Join(tmpDir, "wakatime-cli/master/.git"))
530+
require.NoError(t, err)
531+
532+
defer tmpFile.Close()
533+
534+
_, err = tmpFile.WriteString(fmt.Sprintf("gitdir: %s/wakatime-cli/worktrees/master", tmpDir))
535+
require.NoError(t, err)
536+
537+
return tmpDir
538+
}
539+
459540
func setupTestGitSubmodule(t *testing.T) (fp string) {
460541
tmpDir := t.TempDir()
461542

pkg/project/mercurial.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (m Mercurial) Detect() (Result, bool, error) {
1919
var fp string
2020

2121
// Take only the directory
22-
if fileExists(m.Filepath) {
22+
if fileOrDirExists(m.Filepath) {
2323
fp = filepath.Dir(m.Filepath)
2424
}
2525

@@ -49,7 +49,7 @@ func (m Mercurial) Detect() (Result, bool, error) {
4949

5050
func findHgBranch(fp string) (string, error) {
5151
p := filepath.Join(fp, "branch")
52-
if !fileExists(p) {
52+
if !fileOrDirExists(p) {
5353
return "default", nil
5454
}
5555

0 commit comments

Comments
 (0)