1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
|
require "test_helper"
class TestCommit < Rugged::TestCase
def setup
@repo = FixtureRepo.from_rugged("testrepo.git")
@repo.config['core.abbrev'] = 7
end
def test_lookup_raises_error_if_object_type_does_not_match
assert_raises Rugged::InvalidError do
# blob
Rugged::Commit.lookup(@repo, "fa49b077972391ad58037050f2a75f74e3671e92")
end
assert_raises Rugged::InvalidError do
# tag
Rugged::Commit.lookup(@repo, "0c37a5391bbff43c37f0d0371823a5509eed5b1d")
end
assert_raises Rugged::InvalidError do
# tree
Rugged::Commit.lookup(@repo, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
subclass = Class.new(Rugged::Commit)
assert_raises Rugged::InvalidError do
# blob
subclass.lookup(@repo, "fa49b077972391ad58037050f2a75f74e3671e92")
end
assert_raises Rugged::InvalidError do
# tag
subclass.lookup(@repo, "0c37a5391bbff43c37f0d0371823a5509eed5b1d")
end
assert_raises Rugged::InvalidError do
# tree
subclass.lookup(@repo, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
end
def test_read_commit_data
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
assert_equal obj.oid, oid
assert_equal obj.type, :commit
assert_equal obj.message, "testing\n"
assert_equal obj.time.to_i, 1273360386
assert_equal obj.epoch_time, 1273360386
c = obj.committer
assert_equal c[:name], "Scott Chacon"
assert_equal c[:time].to_i, 1273360386
assert_equal c[:email], "schacon@gmail.com"
c = obj.author
assert_equal c[:name], "Scott Chacon"
assert_equal c[:time].to_i, 1273360386
assert_equal c[:email], "schacon@gmail.com"
assert_equal obj.tree.oid, "181037049a54a1eb5fab404658a3a250b44335d7"
assert_equal [], obj.parents
end
def test_commit_with_multiple_parents
oid = "a4a7dce85cf63874e984719f4fdd239f5145052f"
obj = @repo.lookup(oid)
parents = obj.parents.map {|c| c.oid }
assert parents.include?("9fd738e8f7967c078dceed8190330fc8648ee56a")
assert parents.include?("c47800c7266a2be04c571c04d5a6614691ea99bd")
end
def test_get_parent_oids
oid = "a4a7dce85cf63874e984719f4fdd239f5145052f"
obj = @repo.lookup(oid)
parents = obj.parent_oids
assert parents.include?("9fd738e8f7967c078dceed8190330fc8648ee56a")
assert parents.include?("c47800c7266a2be04c571c04d5a6614691ea99bd")
end
def test_get_tree_oid
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
assert_equal obj.tree_oid, "181037049a54a1eb5fab404658a3a250b44335d7"
end
def test_amend_commit
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
entry = {:type => :blob,
:name => "README.txt",
:oid => "1385f264afb75a56a5bec74243be9b367ba4ca08",
:filemode => 33188}
builder = Rugged::Tree::Builder.new(@repo)
builder << entry
tree_oid = builder.write
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
commit_params = {
:message => "This is the amended commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:tree => tree_oid
}
new_commit_oid = obj.amend(commit_params)
amended_commit = @repo.lookup(new_commit_oid)
assert_equal commit_params[:message], amended_commit.message
assert_equal tree_oid, amended_commit.tree.oid
end
def test_amend_commit_blank_tree
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
commit_params = {
:message => "This is the amended commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person
}
new_commit_oid = obj.amend(commit_params)
amended_commit = @repo.lookup(new_commit_oid)
assert_equal commit_params[:message], amended_commit.message
end
def test_amend_commit_blank_author_and_committer
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
commit_params = {
:message => "This is the amended commit message\n\nThis commit is created from Rugged"
}
new_commit_oid = obj.amend(commit_params)
amended_commit = @repo.lookup(new_commit_oid)
assert_equal commit_params[:message], amended_commit.message
end
def test_amend_commit_blank_message
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
entry = {:type => :blob,
:name => "README.txt",
:oid => "1385f264afb75a56a5bec74243be9b367ba4ca08",
:filemode => 33188}
builder = Rugged::Tree::Builder.new(@repo)
builder << entry
tree_oid = builder.write
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
commit_params = {
:committer => person,
:author => person,
:tree => tree_oid
}
new_commit_oid = obj.amend(commit_params)
amended_commit = @repo.lookup(new_commit_oid)
assert_equal tree_oid, amended_commit.tree.oid
end
def test_header_field
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
expected_header_field = "Scott Chacon <schacon@gmail.com> 1273360386 -0700"
assert_equal expected_header_field, obj.header_field("author")
assert_nil obj.header_field("foobar")
end
def test_header_field?
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
assert_equal true, obj.header_field?("author")
assert_equal false, obj.header_field?("foobar")
end
def test_header
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
expected_header = <<-HEADER
tree 181037049a54a1eb5fab404658a3a250b44335d7
author Scott Chacon <schacon@gmail.com> 1273360386 -0700
committer Scott Chacon <schacon@gmail.com> 1273360386 -0700
HEADER
assert_equal expected_header, obj.header
end
def test_extract_signature
raw_commit = <<-COMMIT
tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
parent 34734e478d6cf50c27c9d69026d93974d052c454
author Ben Burkert <ben@benburkert.com> 1358451456 -0800
committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
cpxtDQQMGYFpXK/71stq
=ozeK
-----END PGP SIGNATURE-----
a simple commit which works
COMMIT
exp_signature = <<-SIGNATURE.strip
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
cpxtDQQMGYFpXK/71stq
=ozeK
-----END PGP SIGNATURE-----
SIGNATURE
exp_signed_data = <<-SIGNEDDATA
tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
parent 34734e478d6cf50c27c9d69026d93974d052c454
author Ben Burkert <ben@benburkert.com> 1358451456 -0800
committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
a simple commit which works
SIGNEDDATA
commit_sha = @repo.write(raw_commit, :commit)
signature, signed_data = Rugged::Commit.extract_signature(@repo, commit_sha, "gpgsig")
assert_equal exp_signature, signature
assert_equal exp_signed_data, signed_data
signature, signed_data = Rugged::Commit.extract_signature(@repo, commit_sha)
assert_equal exp_signature, signature
assert_equal exp_signed_data, signed_data
assert_nil Rugged::Commit.extract_signature(@repo, "8496071c1b46c854b31185ea97743be6a8774479")
# Ask for a tree
assert_raises(Rugged::InvalidError) { Rugged::Commit.extract_signature(@repo, "181037049a54a1eb5fab404658a3a250b44335d7") }
# Ask for a non-existent object
assert_raises(Rugged::OdbError) { Rugged::Commit.extract_signature(@repo, "181037049a54a1eb5fab404658a3a250b44335d8") }
end
def test_create_with_signature
signed_commit = <<-COMMIT
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
parent 8496071c1b46c854b31185ea97743be6a8774479
author Ben Burkert <ben@benburkert.com> 1358451456 -0800
committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
cpxtDQQMGYFpXK/71stq
=ozeK
-----END PGP SIGNATURE-----
a simple commit which works
COMMIT
signature = <<-SIGNATURE.strip
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
cpxtDQQMGYFpXK/71stq
=ozeK
-----END PGP SIGNATURE-----
SIGNATURE
base_data = <<-SIGNEDDATA
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
parent 8496071c1b46c854b31185ea97743be6a8774479
author Ben Burkert <ben@benburkert.com> 1358451456 -0800
committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
a simple commit which works
SIGNEDDATA
id1 = Rugged::Commit::create_with_signature(@repo, base_data, signature, "gpgsig")
id2 = Rugged::Commit::create_with_signature(@repo, base_data, signature)
sig, data = Rugged::Commit::extract_signature(@repo, id1)
assert_equal id1, id2
assert_equal base_data, data
assert_equal signature, sig
raw_commit = Rugged::Commit::lookup(@repo, id1).read_raw.data
assert_equal signed_commit, raw_commit
end
def test_commit_summary
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
commit_id = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
commit = Rugged::Commit.lookup(@repo, commit_id)
assert_equal "This is the commit message", commit.summary
end
end
class CommitWriteTest < Rugged::TestCase
def setup
@source_repo = FixtureRepo.from_rugged("testrepo.git")
@repo = FixtureRepo.clone(@source_repo)
@repo.config['core.abbrev'] = 7
end
def test_write_commit_with_time
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
def test_write_commit_with_time_offset
person = {:name => 'Jake', :email => 'jake@github.com', :time => Time.now, :time_offset => 3600}
oid = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
commit = @repo.lookup(oid)
assert_equal 3600, commit.committer[:time].utc_offset
end
def test_write_commit_without_time
person = {:name => 'Jake', :email => 'jake@github.com'}
oid = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
commit = @repo.lookup(oid)
assert_kind_of Time, commit.committer[:time]
end
def test_write_commit_without_signature
name = 'Rugged User'
email = 'rugged@example.com'
@repo.config['user.name'] = name
@repo.config['user.email'] = email
oid = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
commit = @repo.lookup(oid)
assert_equal name, commit.committer[:name]
assert_equal email, commit.committer[:email]
assert_equal name, commit.author[:name]
assert_equal email, commit.author[:email]
end
def test_write_invalid_parents
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
assert_raises TypeError do
Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:parents => [:invalid_parent],
:committer => person,
:author => person,
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
end
def test_write_empty_email_fails
person = {:name => 'Jake', :email => '', :time => Time.now}
assert_raises Rugged::InvalidError do
Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
end
def test_write_signature_raises_key_error_for_missing_keys
person = {:name => 'Jake', :time => Time.now} # no :email
assert_raises KeyError do
Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
end
end
def test_create_commit_to_s
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
id = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
buffer = Rugged::Commit.create_to_s(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
commit = @repo.lookup(id)
assert_equal buffer, commit.read_raw.data
end
end
class CommitToMboxTest < Rugged::TestCase
def setup
@repo = FixtureRepo.from_libgit2 "diff_format_email"
@repo.config['core.abbrev'] = 7
end
def test_format_to_mbox
assert_equal <<-EOS, @repo.lookup("9264b96c6d104d0e07ae33d3007b6a48246c6f92").to_mbox
From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001
From: Jacques Germishuys <jacquesg@striata.com>
Date: Wed, 9 Apr 2014 20:57:01 +0200
Subject: [PATCH] Modify some content
---
file1.txt | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/file1.txt b/file1.txt
index 94aaae8..af8f41d 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1,15 +1,17 @@
file1.txt
file1.txt
+_file1.txt_
file1.txt
file1.txt
file1.txt
file1.txt
+
+
file1.txt
file1.txt
file1.txt
file1.txt
file1.txt
-file1.txt
-file1.txt
-file1.txt
+_file1.txt_
+_file1.txt_
file1.txt
--
libgit2 #{Rugged.libgit2_version.join('.')}
EOS
end
def test_format_to_mbox_multiple
commit = @repo.lookup("10808fe9c9be5a190c0ba68d1a002233fb363508")
assert_equal <<-EOS, commit.to_mbox(patch_no: 1, total_patches: 2)
From 10808fe9c9be5a190c0ba68d1a002233fb363508 Mon Sep 17 00:00:00 2001
From: Jacques Germishuys <jacquesg@striata.com>
Date: Thu, 10 Apr 2014 19:37:05 +0200
Subject: [PATCH 1/2] Added file2.txt file3.txt
---
file2.txt | 5 +++++
file3.txt | 5 +++++
2 files changed, 10 insertions(+)
create mode 100644 file2.txt
create mode 100644 file3.txt
diff --git a/file2.txt b/file2.txt
new file mode 100644
index 0000000..e909123
--- /dev/null
+++ b/file2.txt
@@ -0,0 +1,5 @@
+file2
+file2
+file2
+file2
+file2
diff --git a/file3.txt b/file3.txt
new file mode 100644
index 0000000..9435022
--- /dev/null
+++ b/file3.txt
@@ -0,0 +1,5 @@
+file3
+file3
+file3
+file3
+file3
--
libgit2 #{Rugged.libgit2_version.join('.')}
EOS
commit = @repo.lookup("873806f6f27e631eb0b23e4b56bea2bfac14a373")
assert_equal <<-EOS, commit.to_mbox(patch_no: 2, total_patches: 2)
From 873806f6f27e631eb0b23e4b56bea2bfac14a373 Mon Sep 17 00:00:00 2001
From: Jacques Germishuys <jacquesg@striata.com>
Date: Thu, 10 Apr 2014 19:37:36 +0200
Subject: [PATCH 2/2] Modified file2.txt, file3.txt
---
file2.txt | 2 +-
file3.txt | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/file2.txt b/file2.txt
index e909123..7aff11d 100644
--- a/file2.txt
+++ b/file2.txt
@@ -1,5 +1,5 @@
file2
file2
file2
-file2
+file2!
file2
diff --git a/file3.txt b/file3.txt
index 9435022..9a2d780 100644
--- a/file3.txt
+++ b/file3.txt
@@ -1,5 +1,5 @@
file3
-file3
+file3!
file3
file3
file3
--
libgit2 #{Rugged.libgit2_version.join('.')}
EOS
end
def test_format_to_mbox_exclude_marker
commit = @repo.lookup("9264b96c6d104d0e07ae33d3007b6a48246c6f92")
assert_equal <<-EOS, commit.to_mbox(exclude_subject_patch_marker: true)
From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001
From: Jacques Germishuys <jacquesg@striata.com>
Date: Wed, 9 Apr 2014 20:57:01 +0200
Subject: Modify some content
---
file1.txt | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/file1.txt b/file1.txt
index 94aaae8..af8f41d 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1,15 +1,17 @@
file1.txt
file1.txt
+_file1.txt_
file1.txt
file1.txt
file1.txt
file1.txt
+
+
file1.txt
file1.txt
file1.txt
file1.txt
file1.txt
-file1.txt
-file1.txt
-file1.txt
+_file1.txt_
+_file1.txt_
file1.txt
--
libgit2 #{Rugged.libgit2_version.join('.')}
EOS
end
def test_format_to_mbox_diff_options
commit = @repo.lookup("9264b96c6d104d0e07ae33d3007b6a48246c6f92")
assert_equal <<-EOS, commit.to_mbox(context_lines: 1, interhunk_lines: 1)
From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001
From: Jacques Germishuys <jacquesg@striata.com>
Date: Wed, 9 Apr 2014 20:57:01 +0200
Subject: [PATCH] Modify some content
---
file1.txt | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/file1.txt b/file1.txt
index 94aaae8..af8f41d 100644
--- a/file1.txt
+++ b/file1.txt
@@ -2,2 +2,3 @@ file1.txt
file1.txt
+_file1.txt_
file1.txt
@@ -6,2 +7,4 @@ file1.txt
file1.txt
+
+
file1.txt
@@ -11,5 +14,4 @@ file1.txt
file1.txt
-file1.txt
-file1.txt
-file1.txt
+_file1.txt_
+_file1.txt_
file1.txt
--
libgit2 #{Rugged.libgit2_version.join('.')}
EOS
end
class TrailersTest < Rugged::TestCase
def setup
@source_repo = FixtureRepo.from_rugged("testrepo.git")
@repo = FixtureRepo.clone(@source_repo)
@repo.config['core.abbrev'] = 7
end
def test_can_parse_trailers
person = {:name => 'Brian', :email => 'brian@gmail.com', :time => Time.now }
commit_oid = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nCo-authored-by: Charles <charliesome@github.com>\nSigned-off-by: Arthur Schreiber <arthurschreiber@github.com>",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => @repo.head.target.tree_oid)
commit = @repo.lookup(commit_oid)
expected = [
["Co-authored-by", "Charles <charliesome@github.com>"],
["Signed-off-by", "Arthur Schreiber <arthurschreiber@github.com>"]
]
assert_equal expected, commit.trailers
end
end
end
|