rugged 0.17.0.b6 → 0.17.0.b7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/Rakefile +3 -1
- data/ext/rugged/rugged.c +30 -0
- data/ext/rugged/rugged.h +9 -0
- data/ext/rugged/rugged_branch.c +306 -0
- data/ext/rugged/rugged_config.c +16 -13
- data/ext/rugged/rugged_index.c +25 -0
- data/ext/rugged/rugged_object.c +6 -2
- data/ext/rugged/rugged_reference.c +11 -18
- data/ext/rugged/rugged_revwalk.c +1 -1
- data/lib/rugged.rb +1 -0
- data/lib/rugged/branch.rb +28 -0
- data/lib/rugged/commit.rb +5 -5
- data/lib/rugged/repository.rb +32 -7
- data/lib/rugged/tag.rb +5 -1
- data/lib/rugged/version.rb +1 -1
- data/test/branch_test.rb +227 -0
- data/test/config_test.rb +1 -1
- data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
- data/test/index_test.rb +31 -0
- data/test/index_test.rb~ +218 -0
- data/test/lib_test.rb +22 -0
- data/test/reference_test.rb +5 -3
- data/vendor/libgit2/Makefile.embed +1 -1
- data/vendor/libgit2/include/git2.h +1 -0
- data/vendor/libgit2/include/git2/branch.h +17 -13
- data/vendor/libgit2/include/git2/checkout.h +83 -22
- data/vendor/libgit2/include/git2/clone.h +6 -3
- data/vendor/libgit2/include/git2/common.h +1 -8
- data/vendor/libgit2/include/git2/config.h +185 -26
- data/vendor/libgit2/include/git2/diff.h +229 -17
- data/vendor/libgit2/include/git2/errors.h +39 -1
- data/vendor/libgit2/include/git2/ignore.h +6 -3
- data/vendor/libgit2/include/git2/indexer.h +1 -0
- data/vendor/libgit2/include/git2/merge.h +1 -1
- data/vendor/libgit2/include/git2/object.h +7 -4
- data/vendor/libgit2/include/git2/odb.h +4 -2
- data/vendor/libgit2/include/git2/odb_backend.h +6 -0
- data/vendor/libgit2/include/git2/oid.h +2 -0
- data/vendor/libgit2/include/git2/pack.h +89 -0
- data/vendor/libgit2/include/git2/refs.h +88 -0
- data/vendor/libgit2/include/git2/refspec.h +0 -8
- data/vendor/libgit2/include/git2/remote.h +34 -1
- data/vendor/libgit2/include/git2/repository.h +238 -6
- data/vendor/libgit2/include/git2/reset.h +4 -1
- data/vendor/libgit2/include/git2/revwalk.h +1 -1
- data/vendor/libgit2/include/git2/status.h +19 -14
- data/vendor/libgit2/include/git2/strarray.h +54 -0
- data/vendor/libgit2/include/git2/submodule.h +451 -45
- data/vendor/libgit2/include/git2/tag.h +16 -0
- data/vendor/libgit2/include/git2/tree.h +2 -2
- data/vendor/libgit2/include/git2/types.h +4 -0
- data/vendor/libgit2/src/amiga/map.c +4 -7
- data/vendor/libgit2/src/attr.c +21 -13
- data/vendor/libgit2/src/attr.h +3 -1
- data/vendor/libgit2/src/attr_file.c +14 -14
- data/vendor/libgit2/src/attr_file.h +6 -5
- data/vendor/libgit2/src/blob.c +22 -12
- data/vendor/libgit2/src/branch.c +62 -66
- data/vendor/libgit2/src/buffer.c +63 -14
- data/vendor/libgit2/src/buffer.h +4 -0
- data/vendor/libgit2/src/cache.c +5 -4
- data/vendor/libgit2/src/checkout.c +381 -159
- data/vendor/libgit2/src/clone.c +221 -94
- data/vendor/libgit2/src/common.h +13 -3
- data/vendor/libgit2/src/compress.c +53 -0
- data/vendor/libgit2/src/compress.h +16 -0
- data/vendor/libgit2/src/config.c +380 -175
- data/vendor/libgit2/src/config.h +2 -5
- data/vendor/libgit2/src/config_file.c +63 -46
- data/vendor/libgit2/src/config_file.h +16 -4
- data/vendor/libgit2/src/crlf.c +4 -3
- data/vendor/libgit2/src/delta.c +491 -0
- data/vendor/libgit2/src/delta.h +112 -0
- data/vendor/libgit2/src/diff.c +310 -67
- data/vendor/libgit2/src/diff.h +10 -1
- data/vendor/libgit2/src/diff_output.c +1030 -337
- data/vendor/libgit2/src/diff_output.h +86 -0
- data/vendor/libgit2/src/errors.c +10 -1
- data/vendor/libgit2/src/fetch.c +108 -24
- data/vendor/libgit2/src/filebuf.c +8 -2
- data/vendor/libgit2/src/fileops.c +342 -177
- data/vendor/libgit2/src/fileops.h +84 -7
- data/vendor/libgit2/src/filter.c +0 -35
- data/vendor/libgit2/src/filter.h +0 -12
- data/vendor/libgit2/src/{compat/fnmatch.c → fnmatch.c} +16 -4
- data/vendor/libgit2/src/{compat/fnmatch.h → fnmatch.h} +4 -3
- data/vendor/libgit2/src/global.c +4 -0
- data/vendor/libgit2/src/ignore.c +122 -23
- data/vendor/libgit2/src/ignore.h +1 -0
- data/vendor/libgit2/src/index.c +56 -10
- data/vendor/libgit2/src/index.h +2 -0
- data/vendor/libgit2/src/indexer.c +8 -9
- data/vendor/libgit2/src/iterator.c +244 -31
- data/vendor/libgit2/src/iterator.h +30 -1
- data/vendor/libgit2/src/message.c +1 -1
- data/vendor/libgit2/src/netops.c +44 -4
- data/vendor/libgit2/src/object.c +80 -69
- data/vendor/libgit2/src/object.h +39 -0
- data/vendor/libgit2/src/odb.c +79 -15
- data/vendor/libgit2/src/odb.h +20 -5
- data/vendor/libgit2/src/odb_pack.c +65 -33
- data/vendor/libgit2/src/oid.c +0 -3
- data/vendor/libgit2/src/pack-objects.c +1315 -0
- data/vendor/libgit2/src/pack-objects.h +87 -0
- data/vendor/libgit2/src/pack.c +36 -12
- data/vendor/libgit2/src/pack.h +1 -0
- data/vendor/libgit2/src/path.c +42 -9
- data/vendor/libgit2/src/path.h +14 -0
- data/vendor/libgit2/src/pkt.c +52 -2
- data/vendor/libgit2/src/pkt.h +10 -0
- data/vendor/libgit2/src/pool.h +11 -0
- data/vendor/libgit2/src/posix.h +8 -0
- data/vendor/libgit2/src/protocol.c +24 -2
- data/vendor/libgit2/src/protocol.h +4 -0
- data/vendor/libgit2/src/reflog.c +1 -1
- data/vendor/libgit2/src/refs.c +292 -124
- data/vendor/libgit2/src/refs.h +4 -2
- data/vendor/libgit2/src/refspec.c +117 -19
- data/vendor/libgit2/src/refspec.h +19 -0
- data/vendor/libgit2/src/remote.c +152 -48
- data/vendor/libgit2/src/remote.h +4 -1
- data/vendor/libgit2/src/repo_template.h +58 -0
- data/vendor/libgit2/src/repository.c +594 -179
- data/vendor/libgit2/src/repository.h +23 -22
- data/vendor/libgit2/src/reset.c +71 -29
- data/vendor/libgit2/src/revparse.c +26 -17
- data/vendor/libgit2/src/revwalk.c +36 -19
- data/vendor/libgit2/src/sha1.h +7 -0
- data/vendor/libgit2/src/{sha1.c → sha1/sha1.c} +0 -0
- data/vendor/libgit2/src/signature.c +12 -10
- data/vendor/libgit2/src/status.c +52 -6
- data/vendor/libgit2/src/submodule.c +1363 -255
- data/vendor/libgit2/src/submodule.h +102 -0
- data/vendor/libgit2/src/tag.c +42 -26
- data/vendor/libgit2/src/thread-utils.h +7 -7
- data/vendor/libgit2/src/transport.h +15 -1
- data/vendor/libgit2/src/transports/git.c +1 -1
- data/vendor/libgit2/src/transports/http.c +197 -36
- data/vendor/libgit2/src/tree.c +3 -3
- data/vendor/libgit2/src/unix/map.c +2 -0
- data/vendor/libgit2/src/unix/posix.h +1 -8
- data/vendor/libgit2/src/util.c +6 -1
- data/vendor/libgit2/src/util.h +7 -0
- data/vendor/libgit2/src/vector.c +16 -0
- data/vendor/libgit2/src/vector.h +1 -0
- data/vendor/libgit2/src/win32/dir.c +8 -21
- data/vendor/libgit2/src/win32/findfile.c +149 -0
- data/vendor/libgit2/src/win32/findfile.h +23 -0
- data/vendor/libgit2/src/win32/posix.h +3 -7
- data/vendor/libgit2/src/win32/posix_w32.c +44 -102
- data/vendor/libgit2/src/win32/pthread.c +68 -0
- data/vendor/libgit2/src/win32/pthread.h +7 -0
- data/vendor/libgit2/src/win32/utf-conv.c +60 -71
- data/vendor/libgit2/src/win32/utf-conv.h +4 -3
- metadata +70 -71
- data/vendor/libgit2/include/git2/windows.h +0 -59
data/ext/rugged/rugged_index.c
CHANGED
@@ -404,6 +404,30 @@ VALUE rb_git_index_writetree(VALUE self)
|
|
404
404
|
return rugged_create_oid(&tree_oid);
|
405
405
|
}
|
406
406
|
|
407
|
+
/*
|
408
|
+
* call-seq:
|
409
|
+
* index.read_tree(tree)
|
410
|
+
*
|
411
|
+
* Clear the current index and start the index again on top of +tree+
|
412
|
+
*
|
413
|
+
* Further index operations (+add+, +update+, +remove+, etc) will
|
414
|
+
* be considered changes on top of +tree+.
|
415
|
+
*/
|
416
|
+
VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
|
417
|
+
{
|
418
|
+
git_index *index;
|
419
|
+
git_tree *tree;
|
420
|
+
int error;
|
421
|
+
|
422
|
+
Data_Get_Struct(self, git_index, index);
|
423
|
+
Data_Get_Struct(rb_tree, git_tree, tree);
|
424
|
+
|
425
|
+
error = git_index_read_tree(index, tree, NULL);
|
426
|
+
rugged_exception_check(error);
|
427
|
+
|
428
|
+
return Qnil;
|
429
|
+
}
|
430
|
+
|
407
431
|
void Init_rugged_index()
|
408
432
|
{
|
409
433
|
/*
|
@@ -431,6 +455,7 @@ void Init_rugged_index()
|
|
431
455
|
|
432
456
|
rb_define_method(rb_cRuggedIndex, "remove", rb_git_index_remove, 1);
|
433
457
|
rb_define_method(rb_cRuggedIndex, "write_tree", rb_git_index_writetree, 0);
|
458
|
+
rb_define_method(rb_cRuggedIndex, "read_tree", rb_git_index_readtree, 1);
|
434
459
|
|
435
460
|
rb_define_singleton_method(rb_cRuggedIndex, "index_pack", rb_git_indexer, 1);
|
436
461
|
|
data/ext/rugged/rugged_object.c
CHANGED
@@ -92,12 +92,16 @@ git_object *rugged_object_load(git_repository *repo, VALUE object_value, git_oty
|
|
92
92
|
|
93
93
|
if (TYPE(object_value) == T_STRING) {
|
94
94
|
git_oid oid;
|
95
|
+
int oid_length = (int)RSTRING_LEN(object_value);
|
95
96
|
int error;
|
96
97
|
|
97
|
-
error =
|
98
|
+
error = git_oid_fromstrn(&oid, RSTRING_PTR(object_value), oid_length);
|
98
99
|
rugged_exception_check(error);
|
99
100
|
|
100
|
-
|
101
|
+
if (oid_length < GIT_OID_HEXSZ)
|
102
|
+
error = git_object_lookup_prefix(&object, repo, &oid, oid_length, type);
|
103
|
+
else
|
104
|
+
error = git_object_lookup(&object, repo, &oid, type);
|
101
105
|
rugged_exception_check(error);
|
102
106
|
|
103
107
|
} else if (rb_obj_is_kind_of(object_value, rb_cRuggedObject)) {
|
@@ -24,13 +24,6 @@
|
|
24
24
|
|
25
25
|
#include "rugged.h"
|
26
26
|
|
27
|
-
#define UNPACK_REFERENCE(_rb_obj, _rugged_obj) {\
|
28
|
-
if (DATA_PTR(_rb_obj) == NULL)\
|
29
|
-
rb_raise(rb_eRuntimeError,\
|
30
|
-
"This Git Reference has been deleted and no longer exists on the repository");\
|
31
|
-
Data_Get_Struct(_rb_obj, git_reference, _rugged_obj);\
|
32
|
-
}
|
33
|
-
|
34
27
|
extern VALUE rb_mRugged;
|
35
28
|
extern VALUE rb_cRuggedRepo;
|
36
29
|
VALUE rb_cRuggedReference;
|
@@ -235,7 +228,7 @@ static VALUE rb_git_ref_target(VALUE self)
|
|
235
228
|
{
|
236
229
|
git_reference *ref;
|
237
230
|
|
238
|
-
|
231
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
239
232
|
|
240
233
|
if (git_reference_type(ref) == GIT_REF_OID) {
|
241
234
|
return rugged_create_oid(git_reference_oid(ref));
|
@@ -265,7 +258,7 @@ static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
|
|
265
258
|
git_reference *ref;
|
266
259
|
int error;
|
267
260
|
|
268
|
-
|
261
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
269
262
|
Check_Type(rb_target, T_STRING);
|
270
263
|
|
271
264
|
if (git_reference_type(ref) == GIT_REF_OID) {
|
@@ -292,7 +285,7 @@ static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
|
|
292
285
|
static VALUE rb_git_ref_type(VALUE self)
|
293
286
|
{
|
294
287
|
git_reference *ref;
|
295
|
-
|
288
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
296
289
|
switch (git_reference_type(ref)) {
|
297
290
|
case GIT_REF_OID:
|
298
291
|
return CSTR2SYM("direct");
|
@@ -312,7 +305,7 @@ static VALUE rb_git_ref_type(VALUE self)
|
|
312
305
|
static VALUE rb_git_ref_packed(VALUE self)
|
313
306
|
{
|
314
307
|
git_reference *ref;
|
315
|
-
|
308
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
316
309
|
|
317
310
|
return git_reference_is_packed(ref) ? Qtrue : Qfalse;
|
318
311
|
}
|
@@ -327,7 +320,7 @@ static VALUE rb_git_ref_reload(VALUE self)
|
|
327
320
|
{
|
328
321
|
int error;
|
329
322
|
git_reference *ref;
|
330
|
-
|
323
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
331
324
|
|
332
325
|
error = git_reference_reload(ref);
|
333
326
|
|
@@ -350,7 +343,7 @@ static VALUE rb_git_ref_reload(VALUE self)
|
|
350
343
|
static VALUE rb_git_ref_name(VALUE self)
|
351
344
|
{
|
352
345
|
git_reference *ref;
|
353
|
-
|
346
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
354
347
|
return rugged_str_new2(git_reference_name(ref), rb_utf8_encoding());
|
355
348
|
}
|
356
349
|
|
@@ -373,7 +366,7 @@ static VALUE rb_git_ref_resolve(VALUE self)
|
|
373
366
|
git_reference *resolved;
|
374
367
|
int error;
|
375
368
|
|
376
|
-
|
369
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
377
370
|
|
378
371
|
error = git_reference_resolve(&resolved, ref);
|
379
372
|
rugged_exception_check(error);
|
@@ -398,7 +391,7 @@ static VALUE rb_git_ref_rename(int argc, VALUE *argv, VALUE self)
|
|
398
391
|
VALUE rb_name, rb_force;
|
399
392
|
int error, force = 0;
|
400
393
|
|
401
|
-
|
394
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
402
395
|
rb_scan_args(argc, argv, "11", &rb_name, &rb_force);
|
403
396
|
|
404
397
|
Check_Type(rb_name, T_STRING);
|
@@ -427,7 +420,7 @@ static VALUE rb_git_ref_delete(VALUE self)
|
|
427
420
|
git_reference *ref;
|
428
421
|
int error;
|
429
422
|
|
430
|
-
|
423
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
431
424
|
|
432
425
|
error = git_reference_delete(ref);
|
433
426
|
rugged_exception_check(error);
|
@@ -495,7 +488,7 @@ static VALUE rb_git_reflog(VALUE self)
|
|
495
488
|
VALUE rb_log;
|
496
489
|
unsigned int i, ref_count;
|
497
490
|
|
498
|
-
|
491
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
499
492
|
|
500
493
|
error = git_reflog_read(&reflog, ref);
|
501
494
|
rugged_exception_check(error);
|
@@ -533,7 +526,7 @@ static VALUE rb_git_reflog_write(int argc, VALUE *argv, VALUE self)
|
|
533
526
|
|
534
527
|
git_oid oid;
|
535
528
|
|
536
|
-
|
529
|
+
RUGGED_UNPACK_REFERENCE(self, ref);
|
537
530
|
|
538
531
|
rb_scan_args(argc, argv, "11", &rb_committer, &rb_message);
|
539
532
|
|
data/ext/rugged/rugged_revwalk.c
CHANGED
data/lib/rugged.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rugged
|
2
|
+
class Branch < Rugged::Reference
|
3
|
+
|
4
|
+
# The object pointed at by the tip of this branch
|
5
|
+
def tip
|
6
|
+
@owner.lookup(self.resolve.target)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ==(other)
|
10
|
+
other.instance_of?(Rugged::Branch) &&
|
11
|
+
other.canonical_name == self.canonical_name
|
12
|
+
end
|
13
|
+
|
14
|
+
# The full name of the branch, as a fully-qualified reference
|
15
|
+
# path.
|
16
|
+
#
|
17
|
+
# This is the same as calling Reference#name for the reference behind
|
18
|
+
# the path
|
19
|
+
alias_method 'canonical_name', 'name'
|
20
|
+
|
21
|
+
# The name of the branch, without a fully-qualified reference path
|
22
|
+
#
|
23
|
+
# E.g. 'master' instead of 'refs/heads/master'
|
24
|
+
def name
|
25
|
+
super.gsub(%r{^(refs/heads/|refs/remotes/)}, '')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/rugged/commit.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module Rugged
|
2
2
|
class Commit
|
3
3
|
|
4
|
+
def self.prettify_message(msg, strip_comments = true)
|
5
|
+
Rugged::prettify_message(msg, strip_comments)
|
6
|
+
end
|
7
|
+
|
4
8
|
def inspect
|
5
|
-
"#<Rugged::Commit:#{object_id} {message: #{message.inspect}, tree: #{tree.inspect}, parents: #{
|
9
|
+
"#<Rugged::Commit:#{object_id} {message: #{message.inspect}, tree: #{tree.inspect}, parents: #{parent_oids}>"
|
6
10
|
end
|
7
11
|
|
8
12
|
# The time when this commit was made effective. This is the same value
|
@@ -22,10 +26,6 @@ module Rugged
|
|
22
26
|
:parents => parents,
|
23
27
|
}
|
24
28
|
end
|
25
|
-
|
26
|
-
def parent_ids
|
27
|
-
parents.map { |parent| parent.oid }
|
28
|
-
end
|
29
29
|
|
30
30
|
def modify(new_args, update_ref=nil)
|
31
31
|
args = self.to_hash.merge(new_args)
|
data/lib/rugged/repository.rb
CHANGED
@@ -107,20 +107,45 @@ module Rugged
|
|
107
107
|
Rugged::Reference.each(self)
|
108
108
|
end
|
109
109
|
|
110
|
-
# All
|
110
|
+
# All the tags in the repository.
|
111
111
|
#
|
112
112
|
# Returns an Enumerable::Enumerator containing all the String tag names.
|
113
113
|
def tags(pattern="")
|
114
114
|
Rugged::Tag.each(self, pattern)
|
115
115
|
end
|
116
116
|
|
117
|
-
# All
|
117
|
+
# All the remotes in the repository.
|
118
118
|
#
|
119
119
|
# Returns an Enumerable::Enumerator containing all the String remote names.
|
120
120
|
def remotes
|
121
121
|
Rugged::Remote.each(self)
|
122
122
|
end
|
123
123
|
|
124
|
+
# All the branches in the repository
|
125
|
+
#
|
126
|
+
# Returns an Enumerable::Enumerator containing Rugged::Branch objects
|
127
|
+
def branches
|
128
|
+
Rugged::Branch.each(self)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Create a new branch in the repository
|
132
|
+
#
|
133
|
+
# name - The name of the branch (without a full reference path)
|
134
|
+
# sha_or_ref - The target of the branch; either a String representing
|
135
|
+
# an OID or a reference name, or a Rugged::Object instance.
|
136
|
+
#
|
137
|
+
# Returns a Rugged::Branch object
|
138
|
+
def create_branch(name, sha_or_ref = "HEAD")
|
139
|
+
case sha_or_ref
|
140
|
+
when Rugged::Object
|
141
|
+
target = sha_or_ref.oid
|
142
|
+
else
|
143
|
+
target = rev_parse_oid(sha_or_ref)
|
144
|
+
end
|
145
|
+
|
146
|
+
Branch.create(self, name, target)
|
147
|
+
end
|
148
|
+
|
124
149
|
# Get the content of a file at a specific revision.
|
125
150
|
#
|
126
151
|
# revision - The String SHA1.
|
@@ -129,13 +154,13 @@ module Rugged
|
|
129
154
|
# Returns a String.
|
130
155
|
def file_at(revision, path)
|
131
156
|
tree = Rugged::Commit.lookup(self, revision).tree
|
132
|
-
|
133
|
-
|
134
|
-
|
157
|
+
begin
|
158
|
+
blob_data = tree.path(path)
|
159
|
+
rescue Rugged::IndexerError
|
135
160
|
return nil
|
136
|
-
|
161
|
+
end
|
137
162
|
blob = Rugged::Blob.lookup(self, blob_data[:oid])
|
138
|
-
|
163
|
+
(blob.type == :blob) ? blob.content : nil
|
139
164
|
end
|
140
165
|
end
|
141
166
|
end
|
data/lib/rugged/tag.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module Rugged
|
2
2
|
class Tag
|
3
3
|
|
4
|
+
def self.prettify_message(msg, strip_comments = true)
|
5
|
+
Rugged::prettify_message(msg, strip_comments)
|
6
|
+
end
|
7
|
+
|
4
8
|
def inspect
|
5
|
-
"#<Rugged::
|
9
|
+
"#<Rugged::Tag:#{object_id} {name: #{name.inspect}, message: #{message.inspect}, target: #{target.inspect}>"
|
6
10
|
end
|
7
11
|
|
8
12
|
def to_hash
|
data/lib/rugged/version.rb
CHANGED
data/test/branch_test.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "test_helper"
|
3
|
+
|
4
|
+
context "Rugged::Branch.each_name" do
|
5
|
+
setup do
|
6
|
+
@path = temp_repo("testrepo.git")
|
7
|
+
@repo = Rugged::Repository.new(@path)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "lists the names of all branches in a bare repository" do
|
11
|
+
assert_equal [
|
12
|
+
"master",
|
13
|
+
"origin/HEAD",
|
14
|
+
"origin/master",
|
15
|
+
"origin/packed",
|
16
|
+
], Rugged::Branch.each_name(@repo).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
test "can list only local branches" do
|
20
|
+
assert_equal ["master"], Rugged::Branch.each_name(@repo, :local).sort
|
21
|
+
end
|
22
|
+
|
23
|
+
test "can list only remote branches" do
|
24
|
+
assert_equal [
|
25
|
+
"origin/HEAD",
|
26
|
+
"origin/master",
|
27
|
+
"origin/packed",
|
28
|
+
], Rugged::Branch.each_name(@repo, :remote).sort
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "Rugged::Branch#tip" do
|
33
|
+
setup do
|
34
|
+
@path = temp_repo("testrepo.git")
|
35
|
+
@repo = Rugged::Repository.new(@path)
|
36
|
+
end
|
37
|
+
|
38
|
+
test "returns the latest commit of the branch" do
|
39
|
+
tip = Rugged::Branch.lookup(@repo, "master").tip
|
40
|
+
|
41
|
+
assert_kind_of Rugged::Commit, tip
|
42
|
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", tip.oid
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "Rugged::Branch.lookup" do
|
47
|
+
setup do
|
48
|
+
@path = temp_repo("testrepo.git")
|
49
|
+
@repo = Rugged::Repository.new(@path)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "can look up local branches" do
|
53
|
+
branch = Rugged::Branch.lookup(@repo, "master")
|
54
|
+
refute_nil branch
|
55
|
+
|
56
|
+
assert_equal "master", branch.name
|
57
|
+
assert_equal "refs/heads/master", branch.canonical_name
|
58
|
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", branch.tip.oid
|
59
|
+
end
|
60
|
+
|
61
|
+
test "can look up remote branches" do
|
62
|
+
branch = Rugged::Branch.lookup(@repo, "origin/packed", :remote)
|
63
|
+
refute_nil branch
|
64
|
+
|
65
|
+
assert_equal "origin/packed", branch.name
|
66
|
+
assert_equal "refs/remotes/origin/packed", branch.canonical_name
|
67
|
+
assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", branch.tip.oid
|
68
|
+
end
|
69
|
+
|
70
|
+
test "can look up branches with non 7-bit ASCII characters" do
|
71
|
+
new_branch = @repo.create_branch("Ångström", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
|
72
|
+
refute_nil new_branch
|
73
|
+
|
74
|
+
retrieved_branch = Rugged::Branch.lookup(@repo, "Ångström")
|
75
|
+
refute_nil retrieved_branch
|
76
|
+
|
77
|
+
assert_equal new_branch, retrieved_branch
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "Rugged::Repository.delete" do
|
82
|
+
setup do
|
83
|
+
@path = temp_repo("testrepo.git")
|
84
|
+
@repo = Rugged::Repository.new(@path)
|
85
|
+
end
|
86
|
+
|
87
|
+
test "deletes a branch from the repository" do
|
88
|
+
branch = @repo.create_branch("test_branch")
|
89
|
+
branch.delete!
|
90
|
+
assert_nil Rugged::Branch.lookup(@repo, "test_branch")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "Rugged::Repository.move" do
|
95
|
+
setup do
|
96
|
+
@path = temp_repo("testrepo.git")
|
97
|
+
@repo = Rugged::Repository.new(@path)
|
98
|
+
end
|
99
|
+
|
100
|
+
test "renames a branch" do
|
101
|
+
branch = @repo.create_branch("test_branch")
|
102
|
+
|
103
|
+
branch.move('other_branch')
|
104
|
+
|
105
|
+
assert_nil Rugged::Branch.lookup(@repo, "test_branch")
|
106
|
+
refute_nil Rugged::Branch.lookup(@repo, "other_branch")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "Rugged::Repository#create_branch" do
|
111
|
+
setup do
|
112
|
+
@path = temp_repo("testrepo.git")
|
113
|
+
@repo = Rugged::Repository.new(@path)
|
114
|
+
end
|
115
|
+
|
116
|
+
test "can create a new branch" do
|
117
|
+
new_branch = @repo.create_branch("test_branch", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
|
118
|
+
|
119
|
+
refute_nil new_branch
|
120
|
+
assert_equal "test_branch", new_branch.name
|
121
|
+
assert_equal "refs/heads/test_branch", new_branch.canonical_name
|
122
|
+
|
123
|
+
refute_nil new_branch.tip
|
124
|
+
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
|
125
|
+
|
126
|
+
refute_nil @repo.branches.find { |p| p.name == "test_branch" }
|
127
|
+
end
|
128
|
+
|
129
|
+
test "can create branches with non 7-bit ASCII names" do
|
130
|
+
branch_name = "A\314\212ngstro\314\210m"
|
131
|
+
new_branch = @repo.create_branch(branch_name, "5b5b025afb0b4c913b4c338a42934a3863bf3644")
|
132
|
+
|
133
|
+
refute_nil new_branch
|
134
|
+
assert_equal branch_name, new_branch.name
|
135
|
+
assert_equal "refs/heads/#{branch_name}", new_branch.canonical_name
|
136
|
+
|
137
|
+
refute_nil new_branch.tip
|
138
|
+
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
|
139
|
+
|
140
|
+
refute_nil @repo.branches.find { |p| p.name == branch_name }
|
141
|
+
end
|
142
|
+
|
143
|
+
test "can create a new branch with an abbreviated sha" do
|
144
|
+
new_branch = @repo.create_branch("test_branch", "5b5b025")
|
145
|
+
|
146
|
+
refute_nil new_branch
|
147
|
+
assert_equal "test_branch", new_branch.name
|
148
|
+
assert_equal "refs/heads/test_branch", new_branch.canonical_name
|
149
|
+
|
150
|
+
refute_nil new_branch.tip
|
151
|
+
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
|
152
|
+
end
|
153
|
+
|
154
|
+
test "can create a new branch from a tag name" do
|
155
|
+
new_branch = @repo.create_branch("test_branch", "refs/tags/v0.9")
|
156
|
+
|
157
|
+
refute_nil new_branch
|
158
|
+
assert_equal "test_branch", new_branch.name
|
159
|
+
assert_equal "refs/heads/test_branch", new_branch.canonical_name
|
160
|
+
|
161
|
+
refute_nil new_branch.tip
|
162
|
+
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
|
163
|
+
end
|
164
|
+
|
165
|
+
test "can create a new branch from implicit head" do
|
166
|
+
new_branch = @repo.create_branch("test_branch")
|
167
|
+
|
168
|
+
refute_nil new_branch
|
169
|
+
assert_equal "test_branch", new_branch.name
|
170
|
+
assert_equal "refs/heads/test_branch", new_branch.canonical_name
|
171
|
+
|
172
|
+
refute_nil new_branch.tip
|
173
|
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
|
174
|
+
end
|
175
|
+
|
176
|
+
test "can create a new branch from explicit head" do
|
177
|
+
new_branch = @repo.create_branch("test_branch", "HEAD")
|
178
|
+
|
179
|
+
refute_nil new_branch
|
180
|
+
assert_equal "test_branch", new_branch.name
|
181
|
+
assert_equal "refs/heads/test_branch", new_branch.canonical_name
|
182
|
+
|
183
|
+
refute_nil new_branch.tip
|
184
|
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
|
185
|
+
end
|
186
|
+
|
187
|
+
test "can create a new branch from a commit object" do
|
188
|
+
new_branch = @repo.create_branch("test_branch", Rugged::Commit.lookup(@repo, "5b5b025afb0b4c913b4c338a42934a3863bf3644"))
|
189
|
+
|
190
|
+
refute_nil new_branch
|
191
|
+
assert_equal "test_branch", new_branch.name
|
192
|
+
assert_equal "refs/heads/test_branch", new_branch.canonical_name
|
193
|
+
|
194
|
+
refute_nil new_branch.tip
|
195
|
+
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
|
196
|
+
end
|
197
|
+
|
198
|
+
test "can not create a new branch from a tree" do
|
199
|
+
assert_raises Rugged::InvalidError do
|
200
|
+
@repo.create_branch("test_branch", Rugged::Tree.lookup(@repo, "f60079018b664e4e79329a7ef9559c8d9e0378d1"))
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
test "can not create a new branch from a blob" do
|
205
|
+
assert_raises Rugged::InvalidError do
|
206
|
+
@repo.create_branch("test_branch", Rugged::Blob.lookup(@repo, "1385f264afb75a56a5bec74243be9b367ba4ca08"))
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
test "can not create a new branch from an unknown branch" do
|
211
|
+
assert_raises Rugged::ReferenceError do
|
212
|
+
@repo.create_branch("test_branch", "i_do_not_exist")
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
test "can not create a new branch from an unknown commit" do
|
217
|
+
assert_raises Rugged::ReferenceError do
|
218
|
+
@repo.create_branch("test_branch", "dd15de908706711b51b7acb24faab726d2b3cb16")
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
test "can not create a new branch from a non canonical branch name" do
|
223
|
+
assert_raises Rugged::ReferenceError do
|
224
|
+
@repo.create_branch("test_branch", "packed")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|