MCPcopy Index your code
hub / github.com/go-git/go-git / TestFilePermissions

Function TestFilePermissions

worktree_test.go:3444–3501  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3442}
3443
3444func TestFilePermissions(t *testing.T) {
3445 // Initialize an in memory repository
3446 remoteUrl := t.TempDir()
3447
3448 inMemoryFs := memfs.New()
3449 remoteFs := osfs.New(remoteUrl)
3450 remoteStorage := filesystem.NewStorage(remoteFs, cache.NewObjectLRUDefault())
3451
3452 remoteRepository, err := Init(remoteStorage, inMemoryFs)
3453 assert.NoError(t, err)
3454
3455 err = util.WriteFile(inMemoryFs, "fileWithExecuteBit", []byte("Initial data"), 0755)
3456 assert.NoError(t, err)
3457
3458 err = util.WriteFile(inMemoryFs, "regularFile", []byte("Initial data"), 0644)
3459 assert.NoError(t, err)
3460
3461 remoteWorktree, err := remoteRepository.Worktree()
3462 assert.NoError(t, err)
3463
3464 _, err = remoteWorktree.Add("fileWithExecuteBit")
3465 assert.NoError(t, err)
3466
3467 _, err = remoteWorktree.Add("regularFile")
3468 assert.NoError(t, err)
3469
3470 _, err = remoteWorktree.Commit("my commit", &CommitOptions{})
3471 assert.NoError(t, err)
3472
3473 worktreePath := t.TempDir()
3474
3475 localRepo, err := PlainClone(worktreePath, false, &CloneOptions{URL: remoteUrl})
3476 assert.NoError(t, err)
3477
3478 localWorktree, err := localRepo.Worktree()
3479 assert.NoError(t, err)
3480
3481 idx, err := localWorktree.r.Storer.Index()
3482 assert.NoError(t, err)
3483
3484 expectedEntries := []index.Entry{
3485 {
3486 Name: "fileWithExecuteBit",
3487 Mode: filemode.Executable,
3488 },
3489 {
3490 Name: "regularFile",
3491 Mode: filemode.Regular,
3492 },
3493 }
3494
3495 assert.Len(t, idx.Entries, len(expectedEntries))
3496
3497 for i, expectedEntry := range expectedEntries {
3498 assert.Equal(t, expectedEntry.Name, idx.Entries[i].Name)
3499 assert.Equal(t, expectedEntry.Mode, idx.Entries[i].Mode)
3500 }
3501}

Callers

nothing calls this directly

Calls 9

NewStorageFunction · 0.92
NewObjectLRUDefaultFunction · 0.92
InitFunction · 0.85
PlainCloneFunction · 0.85
WorktreeMethod · 0.80
CommitMethod · 0.65
IndexMethod · 0.65
AddMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…