                       (if (or (not (string-equal tree head-tree))
                               (yes-or-no-p "The tree was not modified, do you really want to perform an empty commit? "))
                           (let ((commit (git-commit-tree buffer tree head)))
-                            (git-update-ref "HEAD" commit head)
                             (condition-case nil (delete-file ".git/MERGE_HEAD") (error nil))
                             (condition-case nil (delete-file ".git/MERGE_MSG") (error nil))
                             (with-current-buffer buffer (erase-buffer))

            (goto-char (point-min))
            (while (re-search-forward "^Parent: +\\([0-9a-f]+\\)" nil t)
              (unless (string-equal head (match-string 1))
                (push "-p" args)
                (push (match-string 1) args))))
        (setq log-start (point-min)))
      (setq log-end (point-max))
      (setq coding-system-for-write buffer-file-coding-system))
    (git-get-string-sha1
     (with-output-to-string
       (with-current-buffer standard-output
         (let ((env `(("GIT_AUTHOR_NAME" . ,author-name)
                      ("GIT_AUTHOR_EMAIL" . ,author-email)
                      ("GIT_COMMITTER_NAME" . ,(git-get-committer-name))
                      ("GIT_COMMITTER_EMAIL" . ,(git-get-committer-email)))))
           (when author-date (push `("GIT_AUTHOR_DATE" . ,author-date) env))
           (apply #'git-run-command-region
                  buffer log-start log-end env
                  "commit-tree" tree (nreverse args))))))))

(defun git-empty-db-p ()
  "Check if the git db is empty (no commit done yet)."

  (let ((str (git-call-process-env-string nil "symbolic-ref" ref)))
    (and str (car (split-string str "\n")))))

(defun git-update-ref (ref newval &optional oldval reason)
  "Update a reference by calling git-update-ref."
  (let ((args (and oldval (list oldval))))
    (push newval args)
    (push ref args)
    (when reason
     (push reason args)
     (push "-m" args))
    (eq 0 (apply #'git-call-process-env nil nil "update-ref" args))))

(defun git-read-tree (tree &optional index-file)
  "Read a tree into the index file."
