MCPcopy Create free account
hub / github.com/go-git/go-git / TestFilenameNormalization

Method TestFilenameNormalization

worktree_test.go:509–587  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

507}
508
509func (s *WorktreeSuite) TestFilenameNormalization(c *C) {
510 if runtime.GOOS == "windows" {
511 c.Skip("windows paths may contain non utf-8 sequences")
512 }
513
514 url, clean := s.TemporalDir()
515 defer clean()
516
517 path := fixtures.Basic().ByTag("worktree").One().Worktree().Root()
518
519 server, err := PlainClone(url, false, &CloneOptions{
520 URL: path,
521 })
522 c.Assert(err, IsNil)
523
524 filename := "페"
525
526 w, err := server.Worktree()
527 c.Assert(err, IsNil)
528
529 writeFile := func(path string) {
530 err := util.WriteFile(w.Filesystem, path, []byte("foo"), 0755)
531 c.Assert(err, IsNil)
532 }
533
534 writeFile(filename)
535 origHash, err := w.Add(filename)
536 c.Assert(err, IsNil)
537 _, err = w.Commit("foo", &CommitOptions{Author: defaultSignature()})
538 c.Assert(err, IsNil)
539
540 r, err := Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
541 URL: url,
542 })
543 c.Assert(err, IsNil)
544
545 w, err = r.Worktree()
546 c.Assert(err, IsNil)
547
548 status, err := w.Status()
549 c.Assert(err, IsNil)
550 c.Assert(status.IsClean(), Equals, true)
551
552 err = w.Filesystem.Remove(filename)
553 c.Assert(err, IsNil)
554
555 modFilename := norm.NFKD.String(filename)
556 writeFile(modFilename)
557
558 _, err = w.Add(filename)
559 c.Assert(err, IsNil)
560 modHash, err := w.Add(modFilename)
561 c.Assert(err, IsNil)
562 // At this point we've got two files with the same content.
563 // Hence their hashes must be the same.
564 c.Assert(origHash == modHash, Equals, true)
565
566 status, err = w.Status()

Callers

nothing calls this directly

Calls 14

NewStorageFunction · 0.92
PlainCloneFunction · 0.85
defaultSignatureFunction · 0.85
CloneFunction · 0.85
TemporalDirMethod · 0.80
RootMethod · 0.80
WorktreeMethod · 0.80
SkipMethod · 0.65
CommitMethod · 0.65
StringMethod · 0.65
AddMethod · 0.45
StatusMethod · 0.45

Tested by

no test coverage detected