Skip to content

Commit ad8a552

Browse files
committed
git: worktree, canonicalize pathnames when calling Worktree.Add(), Fixes #1460
Ensure that adding files off the filesystem root gets the filenames right. Fixes: Issue #1460
1 parent 00907d9 commit ad8a552

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

worktree_status.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ func (w *Worktree) doAdd(path string, ignorePattern []gitignore.Pattern, skipSta
370370
}
371371
}
372372

373+
// Relative paths only; see: https://github.com/go-git/go-git/issues/1460
374+
// filepath.IsAbs is hilariously bugged on Windows, check by hand
373375
path = filepath.Clean(path)
376+
if string(path[0]) == string(filepath.Separator) {
377+
root := w.Filesystem.Root()
378+
path, _ = filepath.Rel(root, filepath.Join(root, ".", path))
379+
}
374380

375381
if err != nil || !fi.IsDir() {
376382
added, h, err = w.doAddFile(idx, s, path, ignorePattern)

worktree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ func (s *WorktreeSuite) TestAddUntracked() {
15291529
err = util.WriteFile(w.Filesystem, "foo", []byte("FOO"), 0755)
15301530
s.NoError(err)
15311531

1532-
hash, err := w.Add("foo")
1532+
hash, err := w.Add("/foo")
15331533
s.Equal("d96c7efbfec2814ae0301ad054dc8d9fc416c9b5", hash.String())
15341534
s.NoError(err)
15351535

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy