summaryrefslogtreecommitdiff
path: root/include/git2/commit.h
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-04-09 14:08:22 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-04-30 00:41:37 +0200
commit217c029b54e8f1574ae6bc71c4b25533ecff3b6a (patch)
treef8caf68f1027883b5370e057b29946433d100dd8 /include/git2/commit.h
parent041336e6bd9dbd22db29f2294e5db8645efdd46b (diff)
downloadlibgit2-217c029b54e8f1574ae6bc71c4b25533ecff3b6a.tar.gz
commit: safer commit creation with reference updatecmn/commit-create-safe
The current version of the commit creation and amend function are unsafe to use when passing the update_ref parameter, as they do not check that the reference at the moment of update points to what the user expects. Make sure that we're moving history forward when we ask the library to update the reference for us by checking that the first parent of the new commit is the current value of the reference. We also make sure that the ref we're updating hasn't moved between the read and the write. Similarly, when amending a commit, make sure that the current tip of the branch is the commit we're amending.
Diffstat (limited to 'include/git2/commit.h')
-rw-r--r--include/git2/commit.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 834330b5d..fb53a701b 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -254,7 +254,8 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* is not direct, it will be resolved to a direct reference.
* Use "HEAD" to update the HEAD of the current branch and
* make it point to this commit. If the reference doesn't
- * exist yet, it will be created.
+ * exist yet, it will be created. If it does exist, the first
+ * parent must be the tip of this branch.
*
* @param author Signature with author and author time of commit
*
@@ -329,7 +330,7 @@ GIT_EXTERN(int) git_commit_create_v(
*
* The `update_ref` value works as in the regular `git_commit_create()`,
* updating the ref to point to the newly rewritten commit. If you want
- * to amend a commit that is not currently the HEAD of the branch and then
+ * to amend a commit that is not currently the tip of the branch and then
* rewrite the following commits to reach a ref, pass this as NULL and
* update the rest of the commit chain and ref separately.
*