Skip to content

Rename (object path): Access is denied when trying to stage files #55

@Southclaws

Description

@Southclaws

This one was unexpected as I just set up a completely blank repo with one commit using Git version 2.17.1.windows.2:

~/Desktop
 mkdir tmpo

    Directory: C:\Users\Southclaws\Desktop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----

~/Desktop
 cd .\tmpo\

~/Desktop/tmpo
 git init
Initialized empty Git repository in C:/Users/Southclaws/Desktop/tmpo/.git/

tmpo
 git remote add origin https://a-git-repo-i-have-access-to

tmpo
 New-Item .gitkeep

    Directory: C:\Users\Southclaws\Desktop\tmpo

-a----        05/05/2020     16:41              0 .gitkeep

tmpo
 git commit
[master (root-commit) 2651a57] one
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 .gitkeep

Permissions seem fine, I have full access since I created the repo from the same account I am trying to run my own go-git binary from:

tmpo on  master
 (get-acl .).access | ft IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -auto

IdentityReference         FileSystemRights AccessControlType IsInherited                InheritanceFlags
-----------------         ---------------- ----------------- -----------                ----------------
BUILTIN\Users          Modify, Synchronize             Allow        True ContainerInherit, ObjectInherit
NT AUTHORITY\SYSTEM            FullControl             Allow        True ContainerInherit, ObjectInherit
BUILTIN\Administrators         FullControl             Allow        True ContainerInherit, ObjectInherit
CAURINUS\Southclaws            FullControl             Allow        True ContainerInherit, ObjectInherit

And here's the code I quickly wrote for a small proof-of-concept project:

package main

import (
	"os"

	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing/transport/http"
)

func main() {
	if err := run(); err != nil {
		panic(err)
	}
}

func run() error {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	repo, err := git.PlainOpen(wd)
	if err != nil {
		panic(err)
	}
	wt, err := repo.Worktree()
	if err != nil {
		panic(err)
	}
	if err := wt.AddGlob("*"); err != nil {
		panic(err)
	}
	if _, err := wt.Commit("test", nil); err != nil {
		panic(err)
	}
	if err := repo.Push(&git.PushOptions{
		RemoteName: "origin",
		Auth: &http.BasicAuth{
			Username: "Southclaws",
			Password: "a password good enough to post on a github issue",
		},
	}); err != nil {
		panic(err)
	}
	return nil
}

And here's the error that was thrown by the wt.AddGlob call:

panic: rename C:\Users\Southclaws\Desktop\tmpo\.git\objects\pack\tmp_obj_261084259 C:\Users\Southclaws\Desktop\tmpo\.git\objects\e6\9de29bb2d1d6434b8b29ae775ad8c2e48c5391: Access is denied.

goroutine 1 [running]:
main.run(0x7ce040, 0xc000020118)
        E:/Work/gogitpoc/main.go:30 +0x31e
main.main()
        E:/Work/gogitpoc/main.go:11 +0x29

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingwindows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions