File: test_base.rb

package info (click to toggle)
ruby-git 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,124 kB
  • sloc: ruby: 5,385; sh: 507; perl: 64; makefile: 6
file content (109 lines) | stat: -rw-r--r-- 3,299 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../test_helper'

class TestBase < Test::Unit::TestCase

  def setup
    set_file_paths
  end

  def test_add
    in_temp_dir do |path|
      git = Git.clone(@wdir, 'test_add')
      
      create_file('test_add/test_file_1', 'content tets_file_1')
      create_file('test_add/test_file_2', 'content test_file_2')
      create_file('test_add/test_file_3', 'content test_file_3')
      create_file('test_add/test_file_4', 'content test_file_4')
      create_file('test_add/test file with \' quote', 'content test_file_4')

      assert(!git.status.added.assoc('test_file_1'))
      
      # Adding a single file, usign String
      git.add('test_file_1')

      assert(git.status.added.assoc('test_file_1'))
      assert(!git.status.added.assoc('test_file_2'))

      # Adding a single file, using Array
      git.add(['test_file_2'])

      assert(git.status.added.assoc('test_file_2'))
      assert(!git.status.added.assoc('test_file_3'))
      assert(!git.status.added.assoc('test_file_4'))

      # Adding multiple files, using Array
      git.add(['test_file_3','test_file_4', 'test file with \' quote'])

      assert(git.status.added.assoc('test_file_3'))
      assert(git.status.added.assoc('test_file_4'))
      assert(git.status.added.assoc('test file with \' quote'))
      
      git.commit('test_add commit #1')

      assert(git.status.added.empty?)
       
      delete_file('test_add/test_file_3')
      update_file('test_add/test_file_4', 'content test_file_4 update #1')
      create_file('test_add/test_file_5', 'content test_file_5')

      # Adding all files (new, updated or deleted), using :all
      git.add(:all => true)

      assert(git.status.deleted.assoc('test_file_3'))
      assert(git.status.changed.assoc('test_file_4'))
      assert(git.status.added.assoc('test_file_5'))
      
      git.commit('test_add commit #2')
      
      assert(git.status.deleted.empty?)
      assert(git.status.changed.empty?)
      assert(git.status.added.empty?)
      
      delete_file('test_add/test_file_4')
      update_file('test_add/test_file_5', 'content test_file_5 update #1')
      create_file('test_add/test_file_6', 'content test_fiile_6')
      
      # Adding all files (new or updated), without params
      git.add
      
      assert(git.status.deleted.assoc('test_file_4'))
      assert(git.status.changed.assoc('test_file_5'))
      assert(git.status.added.assoc('test_file_6'))
      
      git.commit('test_add commit #3')

      assert(git.status.changed.empty?)
      assert(git.status.added.empty?)
    end
  end

  def test_commit
    in_temp_dir do |path|
      git = Git.clone(@wdir, 'test_commit')
      
      create_file('test_commit/test_file_1', 'content tets_file_1')
      create_file('test_commit/test_file_2', 'content test_file_2')

      git.add('test_file_1')
      git.add('test_file_2')

      base_commit_id = git.log[0].objectish

      git.commit("Test Commit")

      original_commit_id = git.log[0].objectish

      create_file('test_commit/test_file_3', 'content test_file_3')
      
      git.add('test_file_3')

      git.commit(nil, :amend => true)

      assert(git.log[0].objectish != original_commit_id)
      assert(git.log[1].objectish == base_commit_id)
    end
  end

end