12

I'm creating a tool that will allow people to store "solutions" to tests. Since I don't want to reinvent version control, I decided to use git's tree/blob/object stuff -- my idea is to create a git tree object out of the current working directory.

The problem is that I want this tool to not touch the state of the user's repository, except to look up hashes to existing objects of course.

I've looked at both mktree and write-tree, and the former needs ls-tree output and the latter needs to examine the index. Neither of these are what I want.

I'm happy to dive deeper and write the analogs of these commands for the working tree, however I'm having trouble figuring out any lower-level git tools to manipulate trees, blobs, and objects.

Ideally, the user will be able to run:

$ git create-tree .

and git will spit out the hash of the newly created tree object.

dave paola
  • 1,815
  • 3
  • 16
  • 27
  • I don't understand what exactly do you want to do. You want to “not touch the state of the user's repository”, but at the same time create a tree in the same repository? How do you intend to use that tree? – svick Mar 07 '12 at 00:51
  • I'm not using it as "history", I'm just using it as a snapshot of a portion of the repository. It's unconventional. – dave paola Mar 07 '12 at 02:30
  • Okay, but what are you going to do with that snapshot? How are you going to get it out of the repo? – svick Mar 07 '12 at 09:07
  • The test suite is in the repository and needs to remain there with a normal history and available git functionality. There are a series of tests that have a certain order to them, but the code that passes the tests must not be int he repository -- instead, the goal is to illustrate that there is a path of applying changes to the code such that the tests can pass. – dave paola Mar 07 '12 at 16:43

1 Answers1

13

Using git mktree is certainly doable. It reads in ls-tree-formatted text, but you can generate that yourself using whatever mechanism you want.

That said, it may be easier to go ahead and use the index. After all, you're free to specify whatever location you want as the index, via the GIT_INDEX_FILE environment variable. Just set this var to point at some temporary location, create your index however you want, create your tree, and then reset the env var and throw away the temporary index.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347