4

I'm trying to create a basic GIT web UI for GIT bare repos which allows edit (only) of existing files.

For example, considering these two cases:

  • /dir-a/dir-b/dir-c/a-file.txt
  • /a-file.txt

How could I use the Git low level plumbing commands to save the edits? Also, I'm using Grit, not sure if it provides a shortcut to do this.

nulltoken
  • 64,429
  • 20
  • 138
  • 130
Akshay Rawat
  • 4,714
  • 5
  • 40
  • 65

1 Answers1

2

I do not know about Grit, but with Git itself you could do it like this, using the index.

Let's assume that the new content to be stored in dir-a/dir-b/dir-c/a-file.txt is available in /tmp/new-content.txt.

git read-tree HEAD
newhash=$(git hash-object -w --path=dir-a/dir-b/dir-c/a-file.txt /tmp/new-content.txt)
git update-index --cacheinfo 0644 $newhash dir-a/dir-b/dir-c/a-file.txt
newtree=$(git write-tree)
newcommit=$(git commit-tree $newtree -p HEAD -m 'file editedin a bare repository')
git update-ref HEAD $newcommit
Michał Politowski
  • 4,288
  • 3
  • 30
  • 41