I'm trying to remove an array of directories in a git repo and make 1 commit for each directory removed. I'm using Rugged and Gitlab_git (which is more or less just a wrapper around Rugged) and so far I've managed to do everything I need to except the actually deletion and commit.
I don't see anything in the Rugged Readme that explains how to remove an entire tree/directory. I tried using their commit example for a blob and replacing a single file with a direcotry, but It didnt work
I also tried editing the code they had for the tree builder, but it added a commit to my history that showed every file ever in the repo having been added, and then left staging showing the same thing. Nothing was deleted.
oid = repo.write("Removing folder", :blob)
builder = Rugged::Tree::Builder.new(repo)
builder << { :type => :blob, :name => "_delete", :oid => oid, :filemode => 0100644 }
options = {}
options[:tree] = builder.write
options[:author] = { :email => "[email protected]", :name => 'Test Author', :time => Time.now }
options[:committer] = { :email => "[email protected]", :name => 'Test Author', :time => Time.now }
options[:message] ||= "Making a commit via Rugged!"
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
options[:update_ref] = 'HEAD'
Rugged::Commit.create(repo, options)
Any suggestions? Im still a bit fuzzy on the git internals, so maybe thats my issue.
The git index doesn't track directories explicitly, only their contents. To remove a directory, stage the removal of all of its contents.