<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,30 +4,39 @@ require 'framework.rb'
 require 'test/unit'
 require 'tmpdir'
 
-
 # Setup a temporary directory
 TMP_DIR = File.join(TEST_TMP_DIR, &quot;index_test&quot;)
 
-`rm -rf #{TMP_DIR}`
-FileUtils.mkdir_p(TMP_DIR)
-
 def do_git(cmd)
 	puts &quot;Running: #{cmd}&quot;
 	`cd #{TMP_DIR} &amp;&amp; #{cmd}`
 end
 
-do_git('git init &amp;&amp; touch a &amp;&amp; touch b &amp;&amp; git add a b &amp;&amp; git commit -m&quot;First Commit&quot;')
+def setup_git_repository
+	`rm -rf #{TMP_DIR}`
+	FileUtils.mkdir_p(TMP_DIR)
+	do_git('git init &amp;&amp; touch a &amp;&amp; touch b &amp;&amp; git add a b &amp;&amp; git commit -m&quot;First Commit&quot;')
+end
 
 class IndexTest &lt; Test::Unit::TestCase
 
 	def setup
-		@finished = false
-		path = NSURL.alloc.initFileURLWithPath(TMP_DIR)
-		@repo = PBGitRepository.alloc.initWithURL(path)
+		setup_git_repository
+
+		@path = NSURL.alloc.initFileURLWithPath(TMP_DIR)
+		@repo = PBGitRepository.alloc.initWithURL(@path)
 		assert(@repo, &quot;Repository creation failed&quot;)
-		@controller = PBGitIndex.alloc.initWithRepository(@repo, workingDirectory:path)
+		@controller = PBGitIndex.alloc.initWithRepository(@repo, workingDirectory:@path)
+		assert(@controller, &quot;Controller creation failed&quot;)
+
+		# Setup escape from run loop
+		NSNotificationCenter.defaultCenter.addObserver(self,
+			selector:&quot;stopRunLoop:&quot;,
+			name:&quot;PBGitIndexFinishedIndexRefresh&quot;,
+			object:@controller);
 	end
 
+	# Run the default run loop, for up to 2 seconds
 	def run_loop
 		@finished = false
 		runloop = NSRunLoop.currentRunLoop
@@ -41,8 +50,8 @@ class IndexTest &lt; Test::Unit::TestCase
 		return true
 	end
 
-	def refreshFinished(notification)
-		puts &quot;Refresh finished!&quot;
+	# Callback method to stop run loop
+	def stopRunLoop(notification)
 		@finished = true
 	end
 
@@ -51,17 +60,18 @@ class IndexTest &lt; Test::Unit::TestCase
 		assert(run_loop, &quot;Refresh finishes in 2 seconds&quot;)
 	end
 
-	def test_a
-		NSNotificationCenter.defaultCenter.addObserver(self,
-			selector:&quot;refreshFinished:&quot;,
-			name:&quot;PBGitIndexFinishedIndexRefresh&quot;,
-			object:@controller);
 
+
+
+
+	def test_refresh
 		wait_for_refresh
 		assert(@controller.indexChanges.empty?, &quot;No changes&quot;)
+
 		do_git('rm a')
 		wait_for_refresh
 		assert(@controller.indexChanges.count == 1, &quot;One change&quot;)
+
 		do_git('touch a')
 		wait_for_refresh
 		assert(@controller.indexChanges.empty?, &quot;No changes anymore&quot;)
@@ -77,7 +87,9 @@ class IndexTest &lt; Test::Unit::TestCase
 		# 2 == DELETED, see PBChangedFile.h
 		assert_equal(@controller.indexChanges[0].status, 2, &quot;File status has changed&quot;)
 		do_git('git checkout a')
+	end
 
+	def test_refresh_new_file
 		do_git('touch c')
 		wait_for_refresh
 		assert(@controller.indexChanges.count == 1)
@@ -86,9 +98,50 @@ class IndexTest &lt; Test::Unit::TestCase
 		
 		do_git('git add c')
 		wait_for_refresh
-		assert(@controller.indexChanges.count == 1)
+		assert_equal(1, @controller.indexChanges.count, &quot;Just one file changed&quot;)
 		assert_equal(file, @controller.indexChanges[0], &quot;Still the same file&quot;)
 		assert_equal(file.status, 0, &quot;Still new&quot;)
+
+		do_git('git rm --cached c')
+		wait_for_refresh
+		assert_equal(1, @controller.indexChanges.count, &quot;Shouldn't be tracked anymore, but still in other list&quot;)
+		assert_equal(file, @controller.indexChanges[0], &quot;Still the same file&quot;)
+		assert_equal(file.status, 0, &quot;Still new (but only local)&quot;)
+
+		# FIXME: The things below should actually be true / false, but macruby return 0 / 1
+		assert(file.hasUnstagedChanges == 1, &quot;Has unstaged changes&quot;)
+		assert(@controller.indexChanges[0].hasStagedChanges == 0, &quot;But no staged changes&quot;)
+
+		do_git('rm c')
+		wait_for_refresh
+		assert(@controller.indexChanges.empty?, &quot;All files should be gone&quot;)
+
+		# Test an add -&gt; git rm deletion
+		do_git(&quot;touch d &amp;&amp; git add d&quot;)
+		wait_for_refresh
+		assert_equal(1, @controller.indexChanges.count, &quot;Just one changed file&quot;)
+
+		do_git(&quot;git rm -f d&quot;)
+		wait_for_refresh
+		assert(@controller.indexChanges.empty?, &quot;Should be gone again&quot;)
+	end
+
+	def test_remove_existing_file
+		wait_for_refresh
+		do_git(&quot;rm a&quot;)
+		wait_for_refresh
+		assert_equal(1, @controller.indexChanges.count, &quot;Change was noticed&quot;)
+		file = @controller.indexChanges[0]
+		assert_equal(2, file.status, &quot;File was DELETED&quot;)
+		assert(file.hasUnstagedChanges == 1)
+		assert(file.hasStagedChanges == 0)
+
+		do_git(&quot;git rm a&quot;)
+		wait_for_refresh
+		assert_equal(1, @controller.indexChanges.count, &quot;File was removed&quot;)
+		assert_equal(file, @controller.indexChanges[0], &quot;Still the same&quot;)
+		assert(file.hasUnstagedChanges == 0)
+		assert(file.hasStagedChanges == 1)
 	end
 
 end
\ No newline at end of file</diff>
      <filename>test/index.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a3f02b290281602609994ceb13a14402de2afac8</id>
    </parent>
  </parents>
  <author>
    <name>Pieter de Bie</name>
    <email>pdebie@ai.rug.nl</email>
  </author>
  <url>http://github.com/pieter/gitx/commit/30621f13fc591d60956e17e915f2dbdc1ac31e0c</url>
  <id>30621f13fc591d60956e17e915f2dbdc1ac31e0c</id>
  <committed-date>2009-10-01T12:59:19-07:00</committed-date>
  <authored-date>2009-10-01T12:59:19-07:00</authored-date>
  <message>test/index: add more tests</message>
  <tree>52d824a3bc5b4f0510266b583e39bcd01230e11a</tree>
  <committer>
    <name>Pieter de Bie</name>
    <email>pdebie@ai.rug.nl</email>
  </committer>
</commit>
