summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2015-10-21 16:03:04 +0200
committerPatrick Steinhardt <ps@pks.im>2017-02-13 11:01:09 +0100
commit2a503485fae6c93c76bd0465c8b3fad5d9e19f6d (patch)
tree37fb761871bdbd1acfa6feea714c177d7c9cd3dc /include/git2
parentdea7488e93bdd9a0291d518af58b1cde6d71aca9 (diff)
downloadlibgit2-2a503485fae6c93c76bd0465c8b3fad5d9e19f6d.tar.gz
worktree: implement locking mechanisms
Working trees support locking by creating a file `locked` inside the tree's gitdir with an optional reason inside. Support this feature by adding functions to get and set the locking status.
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/worktree.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/include/git2/worktree.h b/include/git2/worktree.h
index 4b045eeb8..62b4b5e79 100644
--- a/include/git2/worktree.h
+++ b/include/git2/worktree.h
@@ -8,6 +8,7 @@
#define INCLUDE_git_worktree_h__
#include "common.h"
+#include "buffer.h"
#include "types.h"
#include "strarray.h"
@@ -76,6 +77,41 @@ GIT_EXTERN(int) git_worktree_validate(const git_worktree *wt);
*/
GIT_EXTERN(int) git_worktree_add(git_worktree **out, git_repository *repo, const char *name, const char *path);
+/*
+ * Lock worktree if not already locked
+ *
+ * Lock a worktree, optionally specifying a reason why the linked
+ * working tree is being locked.
+ *
+ * @param wt Worktree to lock
+ * @param reason Reason why the working tree is being locked
+ * @return 0 on success, non-zero otherwise
+ */
+GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, char *reason);
+
+/**
+ * Unlock a locked worktree
+ *
+ * @param wt Worktree to unlock
+ * @return 0 on success, 1 if worktree was not locked, error-code
+ * otherwise
+ */
+GIT_EXTERN(int) git_worktree_unlock(git_worktree *wt);
+
+/**
+ * Check if worktree is locked
+ *
+ * A worktree may be locked if the linked working tree is stored
+ * on a portable device which is not available.
+ *
+ * @param reason Buffer to store reason in. If NULL no reason is stored.
+ * @param wt Worktree to check
+ * @return 0 when the working tree not locked, a value greater
+ * than zero if it is locked, less than zero if there was an
+ * error
+ */
+GIT_EXTERN(int) git_worktree_is_locked(git_buf *reason, const git_worktree *wt);
+
/** @} */
GIT_END_DECL
#endif