With git2go I do a AddAll() and a CreateCommit() on a newly cloned directory. The Push() works fine and I get all commited files, when I clone the remote to a different place. But if I call git status
in the first directory then I get:
(sorry for the German, and I don't have the correct translation, it means the branch is at the same position as origin/master, 'gelöscht'
means 'deleted'
and 'Unbeobachtete dateien'
means 'unwatched files'
)
Auf Branch master
Ihr Branch ist auf dem selben Stand wie 'origin/master'.
zum Commit vorgemerkte Änderungen:
(benutzen Sie "git reset HEAD <Datei>..." zum Entfernen aus der Staging-Area)
gelöscht: .gitignore
gelöscht: html/.gitignore
gelöscht: images/.gitignore
gelöscht: json/.gitignore
gelöscht: pjs/.gitignore
gelöscht: pjs/test37.pjs
gelöscht: pjs/test37.png
gelöscht: sounds/.gitignore
Unbeobachtete Dateien:
(benutzen Sie "git add <Datei>...", um die Änderungen zum Commit vorzumerken)
.gitignore
html/
images/
json/
pjs/
sounds/
What I would expect is the following:
Nothing to commit. No files changed. (or similar)
My code:
// Add
repo, err := git.OpenRepository(dir)
index, err := repo.Index()
err = index.AddAll([]string{}, git.IndexAddDefault, nil)
treeId, err := index.WriteTreeTo(repo)
tree, err := repo.LookupTree(treeId)
// Commit
sig := &git.Signature{
Name: userName,
Email: userName + "@" + beego.AppConfig.String("userdata::emailserver"),
When: time.Now(),
}
commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
// Push
remote, err := repo.LookupRemote("origin")
err = remote.Push([]string{"refs/heads/master"}, nil, sig, message)
(I took all error handling out, to make it shorter)