rugged 0.26.0b3 → 0.26.0b4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/ext/rugged/extconf.rb +10 -7
  4. data/ext/rugged/rugged.c +4 -6
  5. data/ext/rugged/rugged_repo.c +1 -1
  6. data/ext/rugged/rugged_revwalk.c +4 -4
  7. data/ext/rugged/rugged_tree.c +2 -2
  8. data/lib/rugged/version.rb +1 -1
  9. data/vendor/libgit2/CMakeLists.txt +13 -6
  10. data/vendor/libgit2/COPYING +33 -0
  11. data/vendor/libgit2/include/git2/branch.h +12 -0
  12. data/vendor/libgit2/include/git2/commit.h +6 -3
  13. data/vendor/libgit2/include/git2/common.h +11 -0
  14. data/vendor/libgit2/include/git2/errors.h +2 -0
  15. data/vendor/libgit2/include/git2/index.h +7 -6
  16. data/vendor/libgit2/include/git2/repository.h +91 -0
  17. data/vendor/libgit2/include/git2/stash.h +2 -2
  18. data/vendor/libgit2/include/git2/types.h +3 -0
  19. data/vendor/libgit2/include/git2/worktree.h +161 -0
  20. data/vendor/libgit2/src/attr.c +24 -16
  21. data/vendor/libgit2/src/attr_file.h +1 -1
  22. data/vendor/libgit2/src/attrcache.c +11 -10
  23. data/vendor/libgit2/src/attrcache.h +1 -4
  24. data/vendor/libgit2/src/blob.c +2 -2
  25. data/vendor/libgit2/src/branch.c +63 -0
  26. data/vendor/libgit2/src/buffer.h +2 -1
  27. data/vendor/libgit2/src/cache.c +21 -25
  28. data/vendor/libgit2/src/cache.h +1 -1
  29. data/vendor/libgit2/src/checkout.c +0 -2
  30. data/vendor/libgit2/src/cherrypick.c +2 -2
  31. data/vendor/libgit2/src/clone.c +2 -3
  32. data/vendor/libgit2/src/commit.c +8 -4
  33. data/vendor/libgit2/src/config_file.c +1 -3
  34. data/vendor/libgit2/src/describe.c +1 -3
  35. data/vendor/libgit2/src/diff_driver.c +2 -4
  36. data/vendor/libgit2/src/fetchhead.c +2 -2
  37. data/vendor/libgit2/src/fileops.c +1 -3
  38. data/vendor/libgit2/src/hash.h +5 -3
  39. data/vendor/libgit2/src/hash/hash_collisiondetect.h +57 -0
  40. data/vendor/libgit2/src/hash/sha1dc/sha1.c +1149 -0
  41. data/vendor/libgit2/src/hash/sha1dc/sha1.h +94 -0
  42. data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +361 -0
  43. data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +35 -0
  44. data/vendor/libgit2/src/idxmap.c +133 -0
  45. data/vendor/libgit2/src/idxmap.h +22 -60
  46. data/vendor/libgit2/src/ignore.c +7 -1
  47. data/vendor/libgit2/src/ignore.h +1 -1
  48. data/vendor/libgit2/src/index.c +11 -14
  49. data/vendor/libgit2/src/indexer.c +8 -11
  50. data/vendor/libgit2/src/merge.c +5 -5
  51. data/vendor/libgit2/src/mwindow.c +1 -3
  52. data/vendor/libgit2/src/odb.c +3 -3
  53. data/vendor/libgit2/src/odb.h +3 -0
  54. data/vendor/libgit2/src/odb_mempack.c +11 -18
  55. data/vendor/libgit2/src/offmap.c +83 -0
  56. data/vendor/libgit2/src/offmap.h +14 -34
  57. data/vendor/libgit2/src/oidmap.c +105 -0
  58. data/vendor/libgit2/src/oidmap.h +19 -22
  59. data/vendor/libgit2/src/pack-objects.c +10 -13
  60. data/vendor/libgit2/src/pack.c +17 -26
  61. data/vendor/libgit2/src/path.c +45 -24
  62. data/vendor/libgit2/src/rebase.c +3 -3
  63. data/vendor/libgit2/src/refdb_fs.c +81 -46
  64. data/vendor/libgit2/src/refs.c +13 -3
  65. data/vendor/libgit2/src/remote.c +6 -2
  66. data/vendor/libgit2/src/repository.c +318 -46
  67. data/vendor/libgit2/src/repository.h +5 -2
  68. data/vendor/libgit2/src/revert.c +2 -2
  69. data/vendor/libgit2/src/revwalk.c +6 -8
  70. data/vendor/libgit2/src/settings.c +5 -0
  71. data/vendor/libgit2/src/sortedcache.c +3 -5
  72. data/vendor/libgit2/src/strmap.c +95 -0
  73. data/vendor/libgit2/src/strmap.h +17 -37
  74. data/vendor/libgit2/src/submodule.c +12 -8
  75. data/vendor/libgit2/src/thread-utils.h +6 -0
  76. data/vendor/libgit2/src/transaction.c +5 -17
  77. data/vendor/libgit2/src/transports/local.c +2 -1
  78. data/vendor/libgit2/src/transports/smart.h +2 -0
  79. data/vendor/libgit2/src/transports/smart_protocol.c +3 -1
  80. data/vendor/libgit2/src/tree.c +2 -4
  81. data/vendor/libgit2/src/unix/posix.h +1 -1
  82. data/vendor/libgit2/src/worktree.c +432 -0
  83. data/vendor/libgit2/src/worktree.h +35 -0
  84. metadata +13 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9cc30938d532d92ebcc7271244206e5a2ac5784
4
- data.tar.gz: 9f0d0e5c310a864b9fa686383c62db6487478e83
3
+ metadata.gz: c54465750c07b3141d878bc3ff04483642b28e45
4
+ data.tar.gz: 611f5afabf028493898a84006cf67f3524425b77
5
5
  SHA512:
6
- metadata.gz: a7a3fd2f6319cc78ee065cb0f9c0fdfee71cec7c979210ef07ff3e07c3e509bd55b7b2f19044bcdc0341822e4548b8636ecd328d9b1f8a505c22a99092f019ae
7
- data.tar.gz: 37a7ac4f679d50ce88bb6e9c5547d5397ca21fde8f983d15009df8b02e771183d7dfc4954919c553bdd50caaa11c1f49566559d719e7579c6086275e5b9188e6
6
+ metadata.gz: ac5b58ed5d8bfc749667525d129150d4d4fc5e0b1eb5336dcb6592e394858abec2e873f92c98531044957c29ad6ce24a0e214a13866728aa8ea268c1ff2a34a4
7
+ data.tar.gz: 5267b1068c8f95caca10f21eda59516f12c72c8a597747ef663b1d536766a1a76d948d120948d585d18886b03cc6860b7f47d211c952506a0782a1e281e819ba
data/README.md CHANGED
@@ -22,6 +22,8 @@ You need to have CMake and `pkg-config` installed on your system to be able to b
22
22
  $ brew install cmake
23
23
  ```
24
24
 
25
+ Please follow the above in case installation of the gem fails with `ERROR: CMake is required to build Rugged.`.
26
+
25
27
  If you want to build Rugged with HTTPS and SSH support, check out the list of optional [libgit2 dependencies](https://github.com/libgit2/libgit2#optional-dependencies).
26
28
 
27
29
  If you're using bundler and want to bundle `libgit2` with Rugged, you can use the `:submodules` option:
@@ -20,11 +20,14 @@ def sys(cmd)
20
20
  ret
21
21
  end
22
22
 
23
- def windows?
24
- RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
23
+ MAKE = if Gem.win_platform?
24
+ # On Windows, Ruby-DevKit only has 'make'.
25
+ find_executable('make')
26
+ else
27
+ find_executable('gmake') || find_executable('make')
25
28
  end
26
29
 
27
- if !(MAKE = find_executable('gmake') || find_executable('make'))
30
+ if !MAKE
28
31
  abort "ERROR: GNU make is required to build Rugged."
29
32
  end
30
33
 
@@ -64,7 +67,7 @@ else
64
67
  abort "ERROR: CMake is required to build Rugged."
65
68
  end
66
69
 
67
- if !windows? && !find_executable('pkg-config')
70
+ if !Gem.win_platform? && !find_executable('pkg-config')
68
71
  abort "ERROR: pkg-config is required to build Rugged."
69
72
  end
70
73
 
@@ -73,14 +76,14 @@ else
73
76
 
74
77
  Dir.chdir("build") do
75
78
  # On Windows, Ruby-DevKit is MSYS-based, so ensure to use MSYS Makefiles.
76
- generator = "-G \"MSYS Makefiles\"" if windows?
77
- sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo #{generator}")
79
+ generator = "-G \"MSYS Makefiles\"" if Gem.win_platform?
80
+ sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo #{ENV['CMAKE_FLAGS']} #{generator}")
78
81
  sys(MAKE)
79
82
 
80
83
  # "normal" libraries (and libgit2 builds) get all these when they build but we're doing it
81
84
  # statically so we put the libraries in by hand. It's important that we put the libraries themselves
82
85
  # in $LIBS or the final linking stage won't pick them up
83
- if windows?
86
+ if Gem.win_platform?
84
87
  $LDFLAGS << " " + "-L#{Dir.pwd}/deps/winhttp"
85
88
  $LIBS << " -lwinhttp -lcrypt32 -lrpcrt4 -lole32 -lz"
86
89
  else
@@ -554,17 +554,15 @@ void Init_rugged(void)
554
554
  Init_rugged_rebase();
555
555
 
556
556
  /*
557
- * Sort the repository contents in no particular ordering;
558
- * this sorting is arbitrary, implementation-specific
559
- * and subject to change at any time.
557
+ * Sort the output with the same default time-order method from git.
560
558
  * This is the default sorting for new walkers.
561
559
  */
562
560
  rb_define_const(rb_mRugged, "SORT_NONE", INT2FIX(GIT_SORT_NONE));
563
561
 
564
562
  /*
565
- * Sort the repository contents in topological order
566
- * (parents before children); this sorting mode
567
- * can be combined with time sorting.
563
+ * Sort the repository contents in topological order (parents before
564
+ * children); this sorting mode can be combined with time sorting to
565
+ * produce git's "time-order".
568
566
  */
569
567
  rb_define_const(rb_mRugged, "SORT_TOPO", INT2FIX(GIT_SORT_TOPOLOGICAL));
570
568
 
@@ -1589,7 +1589,7 @@ static int rugged__each_id_cb(const git_oid *id, void *payload)
1589
1589
  /*
1590
1590
  * call-seq:
1591
1591
  * repo.each_id { |id| block }
1592
- * repo.each_id -> Iterator
1592
+ * repo.each_id -> Enumerator
1593
1593
  *
1594
1594
  * Call the given +block+ once with every object ID found in +repo+
1595
1595
  * and all its alternates. Object IDs are passed as 40-character
@@ -428,13 +428,13 @@ static VALUE rb_git_walk_with_opts(int argc, VALUE *argv, VALUE self, int oid_on
428
428
  /*
429
429
  * call-seq:
430
430
  * walker.each { |commit| block }
431
- * walker.each -> Iterator
431
+ * walker.each -> Enumerator
432
432
  *
433
433
  * Perform the walk through the repository, yielding each
434
434
  * one of the commits found as a <tt>Rugged::Commit</tt> instance
435
435
  * to +block+.
436
436
  *
437
- * If no +block+ is given, an +Iterator+ will be returned.
437
+ * If no +block+ is given, an +Enumerator+ will be returned.
438
438
  *
439
439
  * The walker must have been previously set-up before a walk can be performed
440
440
  * (i.e. at least one commit must have been pushed).
@@ -458,13 +458,13 @@ static VALUE rb_git_walker_each(int argc, VALUE *argv, VALUE self)
458
458
  /*
459
459
  * call-seq:
460
460
  * walker.each_oid { |commit| block }
461
- * walker.each_oid -> Iterator
461
+ * walker.each_oid -> Enumerator
462
462
  *
463
463
  * Perform the walk through the repository, yielding each
464
464
  * one of the commit oids found as a <tt>String</tt>
465
465
  * to +block+.
466
466
  *
467
- * If no +block+ is given, an +Iterator+ will be returned.
467
+ * If no +block+ is given, an +Enumerator+ will be returned.
468
468
  *
469
469
  * The walker must have been previously set-up before a walk can be performed
470
470
  * (i.e. at least one commit must have been pushed).
@@ -260,7 +260,7 @@ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, vo
260
260
  /*
261
261
  * call-seq:
262
262
  * tree.walk(mode) { |root, entry| block }
263
- * tree.walk(mode) -> Iterator
263
+ * tree.walk(mode) -> Enumerator
264
264
  *
265
265
  * Walk +tree+ with the given mode (either +:preorder+ or +:postorder+) and yield
266
266
  * to +block+ every entry in +tree+ and all its subtrees, as a +Hash+. The +block+
@@ -270,7 +270,7 @@ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, vo
270
270
  * If the +block+ returns a falsy value, that entry and its sub-entries (in the case
271
271
  * of a folder) will be skipped for the iteration.
272
272
  *
273
- * If no +block+ is given, an +Iterator+ is returned instead.
273
+ * If no +block+ is given, an +Enumerator+ is returned instead.
274
274
  *
275
275
  * tree.walk(:postorder) { |root, entry| puts "#{root}#{entry[:name]} [#{entry[:oid]}]" }
276
276
  *
@@ -4,5 +4,5 @@
4
4
  # For full terms see the included LICENSE file.
5
5
 
6
6
  module Rugged
7
- Version = VERSION = '0.26.0b3'
7
+ Version = VERSION = '0.26.0b4'
8
8
  end
@@ -37,6 +37,7 @@ OPTION( PROFILE "Generate profiling information" OFF )
37
37
  OPTION( ENABLE_TRACE "Enables tracing support" OFF )
38
38
  OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
39
39
 
40
+ OPTION( USE_SHA1DC "Use SHA-1 with collision detection" OFF )
40
41
  OPTION( USE_ICONV "Link with and use iconv library" OFF )
41
42
  OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
42
43
  OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
@@ -292,13 +293,16 @@ ELSE ()
292
293
  ENDIF()
293
294
 
294
295
  # Specify sha1 implementation
295
- IF (WIN32 AND NOT MINGW AND NOT SHA1_TYPE STREQUAL "builtin")
296
- ADD_DEFINITIONS(-DWIN32_SHA1)
296
+ IF (USE_SHA1DC)
297
+ ADD_DEFINITIONS(-DGIT_SHA1_COLLISIONDETECT)
298
+ FILE(GLOB SRC_SHA1 src/hash/hash_collisiondetect.c src/hash/sha1dc/*)
299
+ ELSEIF (WIN32 AND NOT MINGW)
300
+ ADD_DEFINITIONS(-DGIT_SHA1_WIN32)
297
301
  FILE(GLOB SRC_SHA1 src/hash/hash_win32.c)
298
302
  ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
299
- ADD_DEFINITIONS(-DGIT_COMMON_CRYPTO)
300
- ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
301
- ADD_DEFINITIONS(-DOPENSSL_SHA1)
303
+ ADD_DEFINITIONS(-DGIT_SHA1_COMMON_CRYPTO)
304
+ ELSEIF (OPENSSL_FOUND)
305
+ ADD_DEFINITIONS(-DGIT_SHA1_OPENSSL)
302
306
  IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
303
307
  LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
304
308
  ELSE()
@@ -464,7 +468,10 @@ IF (MSVC)
464
468
  # Precompiled headers
465
469
 
466
470
  ELSE ()
467
- SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -Wall -Wextra ${CMAKE_C_FLAGS}")
471
+ SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
472
+
473
+ ADD_C_FLAG_IF_SUPPORTED(-Wall)
474
+ ADD_C_FLAG_IF_SUPPORTED(-Wextra)
468
475
 
469
476
  IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
470
477
  SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
@@ -958,3 +958,36 @@ necessary. Here is a sample; alter the names:
958
958
  That's all there is to it!
959
959
 
960
960
  ----------------------------------------------------------------------
961
+
962
+ The bundled SHA1 collision detection code is licensed under the MIT license:
963
+
964
+ MIT License
965
+
966
+ Copyright (c) 2017:
967
+ Marc Stevens
968
+ Cryptology Group
969
+ Centrum Wiskunde & Informatica
970
+ P.O. Box 94079, 1090 GB Amsterdam, Netherlands
971
+ marc@marc-stevens.nl
972
+
973
+ Dan Shumow
974
+ Microsoft Research
975
+ danshu@microsoft.com
976
+
977
+ Permission is hereby granted, free of charge, to any person obtaining a copy
978
+ of this software and associated documentation files (the "Software"), to deal
979
+ in the Software without restriction, including without limitation the rights
980
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
981
+ copies of the Software, and to permit persons to whom the Software is
982
+ furnished to do so, subject to the following conditions:
983
+
984
+ The above copyright notice and this permission notice shall be included in all
985
+ copies or substantial portions of the Software.
986
+
987
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
988
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
989
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
990
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
991
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
992
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
993
+ SOFTWARE.
@@ -245,6 +245,18 @@ GIT_EXTERN(int) git_branch_upstream_name(
245
245
  GIT_EXTERN(int) git_branch_is_head(
246
246
  const git_reference *branch);
247
247
 
248
+ /**
249
+ * Determine if the current branch is checked out in any linked
250
+ * repository.
251
+ *
252
+ * @param branch Reference to the branch.
253
+ *
254
+ * @return 1 if branch is checked out, 0 if it isn't,
255
+ * error code otherwise.
256
+ */
257
+ GIT_EXTERN(int) git_branch_is_checked_out(
258
+ const git_reference *branch);
259
+
248
260
  /**
249
261
  * Return the name of remote that the remote tracking branch belongs to.
250
262
  *
@@ -255,7 +255,8 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
255
255
  /**
256
256
  * Get an arbitrary header field
257
257
  *
258
- * @param out the buffer to fill
258
+ * @param out the buffer to fill; existing content will be
259
+ * overwritten
259
260
  * @param commit the commit to look in
260
261
  * @param field the header field to return
261
262
  * @return 0 on succeess, GIT_ENOTFOUND if the field does not exist,
@@ -270,8 +271,10 @@ GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit,
270
271
  * `GITERR_INVALID`. If the commit does not have a signature, the
271
272
  * error class will be `GITERR_OBJECT`.
272
273
  *
273
- * @param signature the signature block
274
- * @param signed_data signed data; this is the commit contents minus the signature block
274
+ * @param signature the signature block; existing content will be
275
+ * overwritten
276
+ * @param signed_data signed data; this is the commit contents minus the signature block;
277
+ * existing content will be overwritten
275
278
  * @param repo the repository in which the commit exists
276
279
  * @param commit_id the commit from which to extract the data
277
280
  * @param field the name of the header field containing the signature
@@ -178,6 +178,7 @@ typedef enum {
178
178
  GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION,
179
179
  GIT_OPT_SET_SSL_CIPHERS,
180
180
  GIT_OPT_GET_USER_AGENT,
181
+ GIT_OPT_ENABLE_OFS_DELTA,
181
182
  } git_libgit2_opt_t;
182
183
 
183
184
  /**
@@ -305,6 +306,16 @@ typedef enum {
305
306
  * >
306
307
  * > - `ciphers` is the list of ciphers that are eanbled.
307
308
  *
309
+ * * opts(GIT_OPT_ENABLE_OFS_DELTA, int enabled)
310
+ *
311
+ * > Enable or disable the use of "offset deltas" when creating packfiles,
312
+ * > and the negotiation of them when talking to a remote server.
313
+ * > Offset deltas store a delta base location as an offset into the
314
+ * > packfile from the current location, which provides a shorter encoding
315
+ * > and thus smaller resultant packfiles.
316
+ * > Packfiles containing offset deltas can still be read.
317
+ * > This defaults to enabled.
318
+ *
308
319
  * @param option Option key
309
320
  * @param ... value to set the option
310
321
  * @return 0 on success, <0 on failure
@@ -100,6 +100,8 @@ typedef enum {
100
100
  GITERR_REBASE,
101
101
  GITERR_FILESYSTEM,
102
102
  GITERR_PATCH,
103
+ GITERR_WORKTREE,
104
+ GITERR_SHA1
103
105
  } git_error_t;
104
106
 
105
107
  /**
@@ -575,15 +575,16 @@ GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
575
575
  * This method will fail in bare index instances.
576
576
  *
577
577
  * The `pathspec` is a list of file names or shell glob patterns that will
578
- * matched against files in the repository's working directory. Each file
579
- * that matches will be added to the index (either updating an existing
580
- * entry or adding a new entry). You can disable glob expansion and force
581
- * exact matching with the `GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH` flag.
578
+ * be matched against files in the repository's working directory. Each
579
+ * file that matches will be added to the index (either updating an
580
+ * existing entry or adding a new entry). You can disable glob expansion
581
+ * and force exact matching with the `GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH`
582
+ * flag.
582
583
  *
583
584
  * Files that are ignored will be skipped (unlike `git_index_add_bypath`).
584
585
  * If a file is already tracked in the index, then it *will* be updated
585
- * even if it is ignored. Pass the `GIT_INDEX_ADD_FORCE` flag to
586
- * skip the checking of ignore rules.
586
+ * even if it is ignored. Pass the `GIT_INDEX_ADD_FORCE` flag to skip
587
+ * the checking of ignore rules.
587
588
  *
588
589
  * To emulate `git add -A` and generate an error if the pathspec contains
589
590
  * the exact path of an ignored file (when not using FORCE), add the
@@ -35,6 +35,17 @@ GIT_BEGIN_DECL
35
35
  * @return 0 or an error code
36
36
  */
37
37
  GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path);
38
+ /**
39
+ * Open working tree as a repository
40
+ *
41
+ * Open the working directory of the working tree as a normal
42
+ * repository that can then be worked on.
43
+ *
44
+ * @param out Output pointer containing opened repository
45
+ * @param wt Working tree to open
46
+ * @return 0 or an error code
47
+ */
48
+ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_worktree *wt);
38
49
 
39
50
  /**
40
51
  * Create a "fake" repository to wrap an object database
@@ -334,6 +345,17 @@ GIT_EXTERN(int) git_repository_init_ext(
334
345
  */
335
346
  GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo);
336
347
 
348
+ /**
349
+ * Retrieve the referenced HEAD for the worktree
350
+ *
351
+ * @param out pointer to the reference which will be retrieved
352
+ * @param repo a repository object
353
+ * @param name name of the worktree to retrieve HEAD for
354
+ * @return 0 when successful, error-code otherwise
355
+ */
356
+ GIT_EXTERN(int) git_repository_head_for_worktree(git_reference **out, git_repository *repo,
357
+ const char *name);
358
+
337
359
  /**
338
360
  * Check if a repository's HEAD is detached
339
361
  *
@@ -346,6 +368,20 @@ GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo);
346
368
  */
347
369
  GIT_EXTERN(int) git_repository_head_detached(git_repository *repo);
348
370
 
371
+ /*
372
+ * Check if a worktree's HEAD is detached
373
+ *
374
+ * A worktree's HEAD is detached when it points directly to a
375
+ * commit instead of a branch.
376
+ *
377
+ * @param repo a repository object
378
+ * @param name name of the worktree to retrieve HEAD for
379
+ * @return 1 if HEAD is detached, 0 if its not; error code if
380
+ * there was an error
381
+ */
382
+ GIT_EXTERN(int) git_repository_head_detached_for_worktree(git_repository *repo,
383
+ const char *name);
384
+
349
385
  /**
350
386
  * Check if the current branch is unborn
351
387
  *
@@ -370,6 +406,42 @@ GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo);
370
406
  */
371
407
  GIT_EXTERN(int) git_repository_is_empty(git_repository *repo);
372
408
 
409
+ /**
410
+ * List of items which belong to the git repository layout
411
+ */
412
+ typedef enum {
413
+ GIT_REPOSITORY_ITEM_GITDIR,
414
+ GIT_REPOSITORY_ITEM_WORKDIR,
415
+ GIT_REPOSITORY_ITEM_COMMONDIR,
416
+ GIT_REPOSITORY_ITEM_INDEX,
417
+ GIT_REPOSITORY_ITEM_OBJECTS,
418
+ GIT_REPOSITORY_ITEM_REFS,
419
+ GIT_REPOSITORY_ITEM_PACKED_REFS,
420
+ GIT_REPOSITORY_ITEM_REMOTES,
421
+ GIT_REPOSITORY_ITEM_CONFIG,
422
+ GIT_REPOSITORY_ITEM_INFO,
423
+ GIT_REPOSITORY_ITEM_HOOKS,
424
+ GIT_REPOSITORY_ITEM_LOGS,
425
+ GIT_REPOSITORY_ITEM_MODULES,
426
+ GIT_REPOSITORY_ITEM_WORKTREES
427
+ } git_repository_item_t;
428
+
429
+ /**
430
+ * Get the location of a specific repository file or directory
431
+ *
432
+ * This function will retrieve the path of a specific repository
433
+ * item. It will thereby honor things like the repository's
434
+ * common directory, gitdir, etc. In case a file path cannot
435
+ * exist for a given item (e.g. the working directory of a bare
436
+ * repository), an error is returned.
437
+ *
438
+ * @param out Buffer to store the path at
439
+ * @param repo Repository to get path for
440
+ * @param item The repository item for which to retrieve the path
441
+ * @return 0 on success, otherwise a negative value
442
+ */
443
+ GIT_EXTERN(int) git_repository_item_path(git_buf *out, git_repository *repo, git_repository_item_t item);
444
+
373
445
  /**
374
446
  * Get the path of this repository
375
447
  *
@@ -392,6 +464,17 @@ GIT_EXTERN(const char *) git_repository_path(git_repository *repo);
392
464
  */
393
465
  GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo);
394
466
 
467
+ /**
468
+ * Get the path of the shared common directory for this repository
469
+ *
470
+ * If the repository is bare is not a worktree, the git directory
471
+ * path is returned.
472
+ *
473
+ * @param repo A repository object
474
+ * @return the path to the common dir
475
+ */
476
+ GIT_EXTERN(const char *) git_repository_commondir(git_repository *repo);
477
+
395
478
  /**
396
479
  * Set the path to the working directory for this repository
397
480
  *
@@ -420,6 +503,14 @@ GIT_EXTERN(int) git_repository_set_workdir(
420
503
  */
421
504
  GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
422
505
 
506
+ /**
507
+ * Check if a repository is a linked work tree
508
+ *
509
+ * @param repo Repo to test
510
+ * @return 1 if the repository is a linked work tree, 0 otherwise.
511
+ */
512
+ GIT_EXTERN(int) git_repository_is_worktree(git_repository *repo);
513
+
423
514
  /**
424
515
  * Get the configuration file for this repository.
425
516
  *