summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 12:21:30 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 12:21:30 -0800
commitabcb1453e210beb6de70a69d3501cf842b38636e (patch)
tree0612905ab3ec279694d2780b43274cb332757d1a /tests
parent3cb57d82c301e9b8a16f30f468401e3007845bb7 (diff)
downloadthird_party-ruby-git-abcb1453e210beb6de70a69d3501cf842b38636e.zip
third_party-ruby-git-abcb1453e210beb6de70a69d3501cf842b38636e.tar.gz
third_party-ruby-git-abcb1453e210beb6de70a69d3501cf842b38636e.tar.xz
added branch and checkout functionality
Diffstat (limited to 'tests')
-rw-r--r--tests/test_helper.rb13
-rw-r--r--tests/units/test_branch.rb42
-rw-r--r--tests/units/test_index_ops.rb12
3 files changed, 55 insertions, 12 deletions
diff --git a/tests/test_helper.rb b/tests/test_helper.rb
index cf67576..c55e1f4 100644
--- a/tests/test_helper.rb
+++ b/tests/test_helper.rb
@@ -29,4 +29,17 @@ class Test::Unit::TestCase
FileUtils.rm_r(tmp_path) if remove_after
end
+
+ def new_file(name, contents)
+ File.open(name, 'w') do |f|
+ f.puts contents
+ end
+ end
+
+ def append_file(name, contents)
+ File.open(name, 'a') do |f|
+ f.puts contents
+ end
+ end
+
end \ No newline at end of file
diff --git a/tests/units/test_branch.rb b/tests/units/test_branch.rb
index c1fe9d6..1560c55 100644
--- a/tests/units/test_branch.rb
+++ b/tests/units/test_branch.rb
@@ -46,4 +46,46 @@ class TestBranch < Test::Unit::TestCase
assert_equal(270, @git.branches[:test_branches].gcommit.size)
end
+ def test_branch_create_and_switch
+ in_temp_dir do |path|
+ g = Git.clone(@wbare, 'branch_test')
+ Dir.chdir('branch_test') do
+ assert(!g.branch('new_branch').current)
+ g.branch('other_branch').create
+ g.branch('new_branch').checkout
+ assert(g.branch('new_branch').current)
+
+ assert_equal(1, g.branches.select { |b| b.name == 'new_branch' }.size)
+
+ new_file('test-file1', 'blahblahblah1')
+ new_file('test-file2', 'blahblahblah2')
+ assert(g.status.untracked.assoc('test-file1'))
+
+ g.add(['test-file1', 'test-file2'])
+ assert(!g.status.untracked.assoc('test-file1'))
+
+ g.reset
+ assert(g.status.untracked.assoc('test-file1'))
+ assert(!g.status.added.assoc('test-file1'))
+
+ g.branch('new_branch').delete
+ assert_equal(1, g.branches.select { |b| b.name == 'new_branch' }.size)
+
+ g.branch('master').checkout
+ g.branch('new_branch').delete
+ assert_equal(0, g.branches.select { |b| b.name == 'new_branch' }.size)
+
+ g.checkout('other_branch')
+ assert(g.branch('other_branch').current)
+
+ g.checkout('master')
+ assert(!g.branch('other_branch').current)
+
+ g.checkout(g.branch('other_branch'))
+ assert(g.branch('other_branch').current)
+
+ end
+ end
+ end
+
end \ No newline at end of file
diff --git a/tests/units/test_index_ops.rb b/tests/units/test_index_ops.rb
index b3946b8..de3a9c3 100644
--- a/tests/units/test_index_ops.rb
+++ b/tests/units/test_index_ops.rb
@@ -91,16 +91,4 @@ class TestIndexOps < Test::Unit::TestCase
end
end
- def new_file(name, contents)
- File.open(name, 'w') do |f|
- f.puts contents
- end
- end
-
- def append_file(name, contents)
- File.open(name, 'a') do |f|
- f.puts contents
- end
- end
-
end \ No newline at end of file