Last active
December 4, 2020 21:53
-
-
Save creationix/31828cf1056a9e70db8399be7c33a4ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Using luvit.io and https://github.com/creationix/lua-git | |
local makeChroot = require('coro-fs').chroot | |
local mount = require('git').mount | |
coroutine.wrap(function () | |
local db = mount(makeChroot(".git")) | |
local head = db.getHead() | |
local commit = db.loadAs("commit", head) | |
local tree = db.loadAs("tree", commit.tree) | |
local hasConfig = false | |
local hasHooks = false | |
for _,entry in pairs(tree) do | |
if entry.name == 'config' then hasConfig = true end | |
if entry.name == 'hooks' then hasHooks = true end | |
end | |
local empty = db.saveAs('tree', {}) | |
if not hasConfig then | |
print "Adding empty config folder" | |
tree[#tree+1] = {hash = empty, name = 'config', mode = 16384} | |
end | |
if not hasHooks then | |
print "Adding empty hooks folder" | |
tree[#tree+1] = {hash = empty, name = 'hooks', mode = 16384} | |
end | |
local newTree = db.saveAs('tree', tree) | |
commit.tree = newTree | |
local newCommit = db.saveAs('commit', commit) | |
p("original commit", head) | |
p("new commit", newCommit) | |
end)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can see the generated commit and tree by passing the hash to
git cat-file -p
Then if you like it, move the current branch to the new commit with a hard reset.