я пытаюсь использовать Rugged, чтобы сделать что-то довольно простое: создать и зафиксировать файл, оставив репозиторий в том же состоянии, что и при выполнении:
git init
echo "blah blah blah" > blah.txt
git add blah.txt
git commit -m "write blah.txt"
что оставляет git status
печать
On branch master
nothing to commit, working directory clean
я использую код, адаптированный из readme защищенного репозитория, который сводится к к:
name = "blah.txt"
repo = Rugged::Repository.init_at dir
File.open File.join(dir, name), 'w' do |f|
f.write content
end
oid = Rugged::Blob.from_workdir repo, name
index = repo.index
index.add(:path => name, :oid => oid, :mode => 0100644)
options = {}
options[:tree] = index.write_tree(repo)
options[:author] = { :email => "[email protected]",
:name => 'Test Author',
:time => Time.now }
options[:committer] = { :email => "[email protected]",
:name => 'Test Author',
:time => Time.now }
options[:message] = "write #{ name }"
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
options[:update_ref] = 'HEAD'
commit = Rugged::Commit.create(repo, options)
это, кажется, оставляет репозиторий в правильном состоянии, но рабочий каталог в странном месте с git status
печатью
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: blah.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
blah.txt
я не понимаю, что, по мнению git, происходит в этот момент (blah.txt
подготовлено для удаления?). выполнение git reset --hard
возвращает рабочий каталог в желаемое состояние, насколько я могу судить.
Заранее спасибо за помощь.
repo.head
? - person BroiSatse   schedule 03.07.2014repo.head
возвращает#<Rugged::Reference:70351778973300 {name: "refs/heads/master", target: #<Rugged::Commit:70351778972640 {message: "write blah.txt", tree: #<Rugged::Tree:70351778972520 {oid: 0066195e7906b164d170885e8c341fd1f1027e3d}> <"blah.txt" f0c1bd0931281f8df0574ff2a1e106547b4366cb> , parents: []}>}>
- person nrser   schedule 04.07.2014