rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -19,6 +19,7 @@
19
19
  */
20
20
  extern int git_checkout_iterator(
21
21
  git_iterator *target,
22
+ git_index *index,
22
23
  const git_checkout_options *opts);
23
24
 
24
25
  #endif
@@ -17,9 +17,9 @@
17
17
  #include "git2/commit.h"
18
18
  #include "git2/sys/commit.h"
19
19
 
20
- #define GIT_CHERRY_PICK_FILE_MODE 0666
20
+ #define GIT_CHERRYPICK_FILE_MODE 0666
21
21
 
22
- static int write_cherry_pick_head(
22
+ static int write_cherrypick_head(
23
23
  git_repository *repo,
24
24
  const char *commit_oidstr)
25
25
  {
@@ -27,8 +27,8 @@ static int write_cherry_pick_head(
27
27
  git_buf file_path = GIT_BUF_INIT;
28
28
  int error = 0;
29
29
 
30
- if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_CHERRY_PICK_HEAD_FILE)) >= 0 &&
31
- (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRY_PICK_FILE_MODE)) >= 0 &&
30
+ if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
31
+ (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
32
32
  (error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
33
33
  error = git_filebuf_commit(&file);
34
34
 
@@ -49,7 +49,7 @@ static int write_merge_msg(
49
49
  int error = 0;
50
50
 
51
51
  if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
52
- (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRY_PICK_FILE_MODE)) < 0 ||
52
+ (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
53
53
  (error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
54
54
  goto cleanup;
55
55
 
@@ -64,10 +64,10 @@ cleanup:
64
64
  return error;
65
65
  }
66
66
 
67
- static int cherry_pick_normalize_opts(
67
+ static int cherrypick_normalize_opts(
68
68
  git_repository *repo,
69
- git_cherry_pick_options *opts,
70
- const git_cherry_pick_options *given,
69
+ git_cherrypick_options *opts,
70
+ const git_cherrypick_options *given,
71
71
  const char *their_label)
72
72
  {
73
73
  int error = 0;
@@ -77,10 +77,10 @@ static int cherry_pick_normalize_opts(
77
77
  GIT_UNUSED(repo);
78
78
 
79
79
  if (given != NULL)
80
- memcpy(opts, given, sizeof(git_cherry_pick_options));
80
+ memcpy(opts, given, sizeof(git_cherrypick_options));
81
81
  else {
82
- git_cherry_pick_options default_opts = GIT_CHERRY_PICK_OPTIONS_INIT;
83
- memcpy(opts, &default_opts, sizeof(git_cherry_pick_options));
82
+ git_cherrypick_options default_opts = GIT_CHERRYPICK_OPTIONS_INIT;
83
+ memcpy(opts, &default_opts, sizeof(git_cherrypick_options));
84
84
  }
85
85
 
86
86
  if (!opts->checkout_opts.checkout_strategy)
@@ -95,14 +95,14 @@ static int cherry_pick_normalize_opts(
95
95
  return error;
96
96
  }
97
97
 
98
- static int cherry_pick_state_cleanup(git_repository *repo)
98
+ static int cherrypick_state_cleanup(git_repository *repo)
99
99
  {
100
- const char *state_files[] = { GIT_CHERRY_PICK_HEAD_FILE, GIT_MERGE_MSG_FILE };
100
+ const char *state_files[] = { GIT_CHERRYPICK_HEAD_FILE, GIT_MERGE_MSG_FILE };
101
101
 
102
102
  return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
103
103
  }
104
104
 
105
- static int cherry_pick_seterr(git_commit *commit, const char *fmt)
105
+ static int cherrypick_seterr(git_commit *commit, const char *fmt)
106
106
  {
107
107
  char commit_oidstr[GIT_OID_HEXSZ + 1];
108
108
 
@@ -112,71 +112,71 @@ static int cherry_pick_seterr(git_commit *commit, const char *fmt)
112
112
  return -1;
113
113
  }
114
114
 
115
- int git_cherry_pick_commit(
115
+ int git_cherrypick_commit(
116
116
  git_index **out,
117
117
  git_repository *repo,
118
- git_commit *cherry_pick_commit,
118
+ git_commit *cherrypick_commit,
119
119
  git_commit *our_commit,
120
120
  unsigned int mainline,
121
121
  const git_merge_options *merge_opts)
122
122
  {
123
123
  git_commit *parent_commit = NULL;
124
- git_tree *parent_tree = NULL, *our_tree = NULL, *cherry_pick_tree = NULL;
124
+ git_tree *parent_tree = NULL, *our_tree = NULL, *cherrypick_tree = NULL;
125
125
  int parent = 0, error = 0;
126
126
 
127
- assert(out && repo && cherry_pick_commit && our_commit);
127
+ assert(out && repo && cherrypick_commit && our_commit);
128
128
 
129
- if (git_commit_parentcount(cherry_pick_commit) > 1) {
129
+ if (git_commit_parentcount(cherrypick_commit) > 1) {
130
130
  if (!mainline)
131
- return cherry_pick_seterr(cherry_pick_commit,
131
+ return cherrypick_seterr(cherrypick_commit,
132
132
  "Mainline branch is not specified but %s is a merge commit");
133
133
 
134
134
  parent = mainline;
135
135
  } else {
136
136
  if (mainline)
137
- return cherry_pick_seterr(cherry_pick_commit,
137
+ return cherrypick_seterr(cherrypick_commit,
138
138
  "Mainline branch specified but %s is not a merge commit");
139
139
 
140
- parent = git_commit_parentcount(cherry_pick_commit);
140
+ parent = git_commit_parentcount(cherrypick_commit);
141
141
  }
142
142
 
143
143
  if (parent &&
144
- ((error = git_commit_parent(&parent_commit, cherry_pick_commit, (parent - 1))) < 0 ||
144
+ ((error = git_commit_parent(&parent_commit, cherrypick_commit, (parent - 1))) < 0 ||
145
145
  (error = git_commit_tree(&parent_tree, parent_commit)) < 0))
146
146
  goto done;
147
147
 
148
- if ((error = git_commit_tree(&cherry_pick_tree, cherry_pick_commit)) < 0 ||
148
+ if ((error = git_commit_tree(&cherrypick_tree, cherrypick_commit)) < 0 ||
149
149
  (error = git_commit_tree(&our_tree, our_commit)) < 0)
150
150
  goto done;
151
151
 
152
- error = git_merge_trees(out, repo, parent_tree, our_tree, cherry_pick_tree, merge_opts);
152
+ error = git_merge_trees(out, repo, parent_tree, our_tree, cherrypick_tree, merge_opts);
153
153
 
154
154
  done:
155
155
  git_tree_free(parent_tree);
156
156
  git_tree_free(our_tree);
157
- git_tree_free(cherry_pick_tree);
157
+ git_tree_free(cherrypick_tree);
158
158
  git_commit_free(parent_commit);
159
159
 
160
160
  return error;
161
161
  }
162
162
 
163
- int git_cherry_pick(
163
+ int git_cherrypick(
164
164
  git_repository *repo,
165
165
  git_commit *commit,
166
- const git_cherry_pick_options *given_opts)
166
+ const git_cherrypick_options *given_opts)
167
167
  {
168
- git_cherry_pick_options opts;
168
+ git_cherrypick_options opts;
169
169
  git_reference *our_ref = NULL;
170
170
  git_commit *our_commit = NULL;
171
171
  char commit_oidstr[GIT_OID_HEXSZ + 1];
172
172
  const char *commit_msg, *commit_summary;
173
173
  git_buf their_label = GIT_BUF_INIT;
174
- git_index *index_new = NULL, *index_repo = NULL;
174
+ git_index *index_new = NULL;
175
175
  int error = 0;
176
176
 
177
177
  assert(repo && commit);
178
178
 
179
- GITERR_CHECK_VERSION(given_opts, GIT_CHERRY_PICK_OPTIONS_VERSION, "git_cherry_pick_options");
179
+ GITERR_CHECK_VERSION(given_opts, GIT_CHERRYPICK_OPTIONS_VERSION, "git_cherrypick_options");
180
180
 
181
181
  if ((error = git_repository__ensure_not_bare(repo, "cherry-pick")) < 0)
182
182
  return error;
@@ -191,25 +191,22 @@ int git_cherry_pick(
191
191
 
192
192
  if ((error = write_merge_msg(repo, commit_msg)) < 0 ||
193
193
  (error = git_buf_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
194
- (error = cherry_pick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
195
- (error = write_cherry_pick_head(repo, commit_oidstr)) < 0 ||
194
+ (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
195
+ (error = write_cherrypick_head(repo, commit_oidstr)) < 0 ||
196
196
  (error = git_repository_head(&our_ref, repo)) < 0 ||
197
197
  (error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJ_COMMIT)) < 0 ||
198
- (error = git_cherry_pick_commit(&index_new, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 ||
199
- (error = git_merge__indexes(repo, index_new)) < 0 ||
200
- (error = git_repository_index(&index_repo, repo)) < 0 ||
201
- (error = git_merge__append_conflicts_to_merge_msg(repo, index_repo)) < 0 ||
202
- (error = git_checkout_index(repo, index_repo, &opts.checkout_opts)) < 0)
198
+ (error = git_cherrypick_commit(&index_new, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 ||
199
+ (error = git_merge__check_result(repo, index_new)) < 0 ||
200
+ (error = git_merge__append_conflicts_to_merge_msg(repo, index_new)) < 0 ||
201
+ (error = git_checkout_index(repo, index_new, &opts.checkout_opts)) < 0)
203
202
  goto on_error;
204
-
205
203
  goto done;
206
204
 
207
205
  on_error:
208
- cherry_pick_state_cleanup(repo);
206
+ cherrypick_state_cleanup(repo);
209
207
 
210
208
  done:
211
209
  git_index_free(index_new);
212
- git_index_free(index_repo);
213
210
  git_commit_free(our_commit);
214
211
  git_reference_free(our_ref);
215
212
  git_buf_free(&their_label);
@@ -217,10 +214,10 @@ done:
217
214
  return error;
218
215
  }
219
216
 
220
- int git_cherry_pick_init_options(
221
- git_cherry_pick_options *opts, unsigned int version)
217
+ int git_cherrypick_init_options(
218
+ git_cherrypick_options *opts, unsigned int version)
222
219
  {
223
220
  GIT_INIT_STRUCTURE_FROM_TEMPLATE(
224
- opts, version, git_cherry_pick_options, GIT_CHERRY_PICK_OPTIONS_INIT);
221
+ opts, version, git_cherrypick_options, GIT_CHERRYPICK_OPTIONS_INIT);
225
222
  return 0;
226
223
  }
@@ -24,6 +24,8 @@
24
24
  #include "repository.h"
25
25
  #include "odb.h"
26
26
 
27
+ static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature);
28
+
27
29
  static int create_branch(
28
30
  git_reference **branch,
29
31
  git_repository *repo,
@@ -142,9 +144,9 @@ static int update_head_to_remote(
142
144
  const git_signature *signature,
143
145
  const char *reflog_message)
144
146
  {
145
- int error = 0, found_branch = 0;
147
+ int error = 0;
146
148
  size_t refs_len;
147
- git_refspec dummy_spec, *refspec;
149
+ git_refspec *refspec;
148
150
  const git_remote_head *remote_head, **refs;
149
151
  const git_oid *remote_head_id;
150
152
  git_buf remote_master_name = GIT_BUF_INIT;
@@ -153,28 +155,30 @@ static int update_head_to_remote(
153
155
  if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0)
154
156
  return error;
155
157
 
156
- /* Did we just clone an empty repository? */
157
- if (refs_len == 0)
158
+ /* We cloned an empty repository or one with an unborn HEAD */
159
+ if (refs_len == 0 || strcmp(refs[0]->name, GIT_HEAD_FILE))
158
160
  return setup_tracking_config(
159
161
  repo, "master", GIT_REMOTE_ORIGIN, GIT_REFS_HEADS_MASTER_FILE);
160
162
 
161
- error = git_remote_default_branch(&branch, remote);
162
- if (error == GIT_ENOTFOUND) {
163
- git_buf_puts(&branch, GIT_REFS_HEADS_MASTER_FILE);
164
- } else {
165
- found_branch = 1;
166
- }
167
-
168
- /* Get the remote's HEAD. This is always the first ref in the list. */
163
+ /* We know we have HEAD, let's see where it points */
169
164
  remote_head = refs[0];
170
165
  assert(remote_head);
171
166
 
172
167
  remote_head_id = &remote_head->oid;
168
+
169
+ error = git_remote_default_branch(&branch, remote);
170
+ if (error == GIT_ENOTFOUND) {
171
+ error = git_repository_set_head_detached(
172
+ repo, remote_head_id, signature, reflog_message);
173
+ goto cleanup;
174
+ }
175
+
173
176
  refspec = git_remote__matching_refspec(remote, git_buf_cstr(&branch));
174
177
 
175
178
  if (refspec == NULL) {
176
- memset(&dummy_spec, 0, sizeof(git_refspec));
177
- refspec = &dummy_spec;
179
+ giterr_set(GITERR_NET, "the remote's default branch does not fit the refspec configuration");
180
+ error = GIT_EINVALIDSPEC;
181
+ goto cleanup;
178
182
  }
179
183
 
180
184
  /* Determine the remote tracking reference name from the local master */
@@ -182,21 +186,18 @@ static int update_head_to_remote(
182
186
  &remote_master_name,
183
187
  refspec,
184
188
  git_buf_cstr(&branch))) < 0)
185
- return error;
189
+ goto cleanup;
186
190
 
187
- if (found_branch) {
188
- error = update_head_to_new_branch(
189
- repo,
190
- remote_head_id,
191
- git_buf_cstr(&branch),
192
- signature, reflog_message);
193
- } else {
194
- error = git_repository_set_head_detached(
195
- repo, remote_head_id, signature, reflog_message);
196
- }
191
+ error = update_head_to_new_branch(
192
+ repo,
193
+ remote_head_id,
194
+ git_buf_cstr(&branch),
195
+ signature, reflog_message);
197
196
 
197
+ cleanup:
198
198
  git_buf_free(&remote_master_name);
199
199
  git_buf_free(&branch);
200
+
200
201
  return error;
201
202
  }
202
203
 
@@ -229,6 +230,29 @@ cleanup:
229
230
  return retcode;
230
231
  }
231
232
 
233
+ static int default_repository_create(git_repository **out, const char *path, int bare, void *payload)
234
+ {
235
+ GIT_UNUSED(payload);
236
+
237
+ return git_repository_init(out, path, bare);
238
+ }
239
+
240
+ static int default_remote_create(
241
+ git_remote **out,
242
+ git_repository *repo,
243
+ const char *name,
244
+ const char *url,
245
+ void *payload)
246
+ {
247
+ int error;
248
+ git_remote_callbacks *callbacks = payload;
249
+
250
+ if ((error = git_remote_create(out, repo, name, url)) < 0)
251
+ return error;
252
+
253
+ return git_remote_set_callbacks(*out, callbacks);
254
+ }
255
+
232
256
  /*
233
257
  * submodules?
234
258
  */
@@ -241,8 +265,9 @@ static int create_and_configure_origin(
241
265
  {
242
266
  int error;
243
267
  git_remote *origin = NULL;
244
- const char *name;
245
268
  char buf[GIT_PATH_MAX];
269
+ git_remote_create_cb remote_create = options->remote_cb;
270
+ void *payload = options->remote_cb_payload;
246
271
 
247
272
  /* If the path exists and is a dir, the url should be the absolute path */
248
273
  if (git_path_root(url) < 0 && git_path_exists(url) && git_path_isdir(url)) {
@@ -252,14 +277,12 @@ static int create_and_configure_origin(
252
277
  url = buf;
253
278
  }
254
279
 
255
- name = options->remote_name ? options->remote_name : "origin";
256
- if ((error = git_remote_create(&origin, repo, name, url)) < 0)
257
- goto on_error;
258
-
259
- if (options->ignore_cert_errors)
260
- git_remote_check_cert(origin, 0);
280
+ if (!remote_create) {
281
+ remote_create = default_remote_create;
282
+ payload = (void *)&options->remote_callbacks;
283
+ }
261
284
 
262
- if ((error = git_remote_set_callbacks(origin, &options->remote_callbacks)) < 0)
285
+ if ((error = remote_create(&origin, repo, "origin", url, payload)) < 0)
263
286
  goto on_error;
264
287
 
265
288
  if ((error = git_remote_save(origin)) < 0)
@@ -307,7 +330,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
307
330
  return error;
308
331
  }
309
332
 
310
- int git_clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch, const git_signature *signature)
333
+ static int clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch, const git_signature *signature)
311
334
  {
312
335
  int error;
313
336
  git_buf reflog_message = GIT_BUF_INIT;
@@ -335,7 +358,7 @@ int git_clone_into(git_repository *repo, git_remote *_remote, const git_checkout
335
358
  git_remote_set_update_fetchhead(remote, 0);
336
359
  git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
337
360
 
338
- if ((error = git_remote_fetch(remote, signature, git_buf_cstr(&reflog_message))) != 0)
361
+ if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
339
362
  goto cleanup;
340
363
 
341
364
  error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));
@@ -347,27 +370,30 @@ cleanup:
347
370
  return error;
348
371
  }
349
372
 
350
- int git_clone__should_clone_local(const char *url, git_clone_local_t local)
373
+ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local)
351
374
  {
352
- const char *path;
353
- int is_url;
375
+ git_buf fromurl = GIT_BUF_INIT;
376
+ const char *path = url_or_path;
377
+ bool is_url, is_local;
354
378
 
355
379
  if (local == GIT_CLONE_NO_LOCAL)
356
- return false;
380
+ return 0;
357
381
 
358
- is_url = !git__prefixcmp(url, "file://");
359
-
360
- if (is_url && local != GIT_CLONE_LOCAL && local != GIT_CLONE_LOCAL_NO_LINKS )
361
- return false;
382
+ if ((is_url = git_path_is_local_file_url(url_or_path)) != 0) {
383
+ if (git_path_fromurl(&fromurl, url_or_path) < 0) {
384
+ is_local = -1;
385
+ goto done;
386
+ }
362
387
 
363
- path = url;
364
- if (is_url)
365
- path = url + strlen("file://");
388
+ path = fromurl.ptr;
389
+ }
366
390
 
367
- if ((git_path_exists(path) && git_path_isdir(path)) && local != GIT_CLONE_NO_LOCAL)
368
- return true;
391
+ is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) &&
392
+ git_path_isdir(path);
369
393
 
370
- return false;
394
+ done:
395
+ git_buf_free(&fromurl);
396
+ return is_local;
371
397
  }
372
398
 
373
399
  int git_clone(
@@ -381,6 +407,7 @@ int git_clone(
381
407
  git_remote *origin;
382
408
  git_clone_options options = GIT_CLONE_OPTIONS_INIT;
383
409
  uint32_t rmdir_flags = GIT_RMDIR_REMOVE_FILES;
410
+ git_repository_create_cb repository_cb;
384
411
 
385
412
  assert(out && url && local_path);
386
413
 
@@ -400,20 +427,28 @@ int git_clone(
400
427
  if (git_path_exists(local_path))
401
428
  rmdir_flags |= GIT_RMDIR_SKIP_ROOT;
402
429
 
403
- if ((error = git_repository_init(&repo, local_path, options.bare)) < 0)
430
+ if (options.repository_cb)
431
+ repository_cb = options.repository_cb;
432
+ else
433
+ repository_cb = default_repository_create;
434
+
435
+ if ((error = repository_cb(&repo, local_path, options.bare, options.repository_cb_payload)) < 0)
404
436
  return error;
405
437
 
406
438
  if (!(error = create_and_configure_origin(&origin, repo, url, &options))) {
407
- if (git_clone__should_clone_local(url, options.local)) {
408
- int link = options.local != GIT_CLONE_LOCAL_NO_LINKS;
409
- error = git_clone_local_into(
439
+ int clone_local = git_clone__should_clone_local(url, options.local);
440
+ int link = options.local != GIT_CLONE_LOCAL_NO_LINKS;
441
+
442
+ if (clone_local == 1)
443
+ error = clone_local_into(
410
444
  repo, origin, &options.checkout_opts,
411
445
  options.checkout_branch, link, options.signature);
412
- } else {
413
- error = git_clone_into(
446
+ else if (clone_local == 0)
447
+ error = clone_into(
414
448
  repo, origin, &options.checkout_opts,
415
449
  options.checkout_branch, options.signature);
416
- }
450
+ else
451
+ error = -1;
417
452
 
418
453
  git_remote_free(origin);
419
454
  }
@@ -452,6 +487,9 @@ static const char *repository_base(git_repository *repo)
452
487
  static bool can_link(const char *src, const char *dst, int link)
453
488
  {
454
489
  #ifdef GIT_WIN32
490
+ GIT_UNUSED(src);
491
+ GIT_UNUSED(dst);
492
+ GIT_UNUSED(link);
455
493
  return false;
456
494
  #else
457
495
 
@@ -470,7 +508,7 @@ static bool can_link(const char *src, const char *dst, int link)
470
508
  #endif
471
509
  }
472
510
 
473
- int git_clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature)
511
+ static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature)
474
512
  {
475
513
  int error, flags;
476
514
  git_repository *src;
@@ -515,7 +553,7 @@ int git_clone_local_into(git_repository *repo, git_remote *remote, const git_che
515
553
 
516
554
  git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
517
555
 
518
- if ((error = git_remote_fetch(remote, signature, git_buf_cstr(&reflog_message))) != 0)
556
+ if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
519
557
  goto cleanup;
520
558
 
521
559
  error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));