views.status: Allow staging untracked files
[git-cola.git] / test / test_cola_models_classic.py
blob79df22f9d3366148e316545a7391af73b5519a28
1 """Covers interfaces used by the classic view."""
2 import os
4 import helper
5 from cola.models.main import MainModel
8 class ClassicModelTestCase(helper.TestCase):
9 """Tests interfaces used by the classic view."""
11 def setup_baseline_repo(self, commit=True):
12 """Create a baseline repo for testing."""
13 self.shell("""
14 git init >/dev/null &&
15 touch the-file &&
16 git add the-file
17 """)
18 if commit:
19 self.shell("git commit -s -m'Initial commit' >/dev/null")
21 def test_everything(self):
22 """Test the MainModel.everything() method."""
23 self.setup_baseline_repo()
24 self.shell('touch other-file')
26 model = MainModel(cwd=os.getcwd())
27 model.update_status()
29 everything = model.everything()
30 self.assertTrue('the-file' in everything)
31 self.assertTrue('other-file' in everything)
33 def test_stage_paths_untracked(self):
34 """Test stage_paths() with an untracked file."""
35 self.setup_baseline_repo()
36 self.shell("""
37 mkdir -p foo/bar &&
38 touch foo/bar/baz
39 """)
40 model = MainModel(cwd=os.getcwd())
41 model.stage_paths(['foo'])
43 self.assertTrue('foo/bar/baz' in model.staged)
44 self.assertTrue('foo/bar/baz' not in model.modified)
45 self.assertTrue('foo/bar/baz' not in model.untracked)
47 def test_unstage_paths(self):
48 """Test a simple usage of unstage_paths()."""
49 self.setup_baseline_repo()
50 self.shell("""
51 echo change > the-file &&
52 git add the-file
53 """)
55 model = MainModel(cwd=os.getcwd())
56 model.unstage_paths(['the-file'])
58 self.assertTrue('the-file' not in model.staged)
59 self.assertTrue('the-file' in model.modified)
61 def test_unstage_paths_init(self):
62 """Test unstage_paths() on the root commit."""
63 self.setup_baseline_repo(commit=False)
65 model = MainModel(cwd=os.getcwd())
66 model.unstage_paths(['the-file'])
68 self.assertTrue('the-file' not in model.staged)
69 self.assertTrue('the-file' in model.untracked)
71 def test_unstage_paths_subdir(self):
72 """Test unstage_paths() in a subdirectory."""
73 self.setup_baseline_repo()
74 self.shell("""
75 mkdir -p foo/bar &&
76 touch foo/bar/baz &&
77 git add foo/bar/baz
78 """)
79 model = MainModel(os.getcwd())
80 model.unstage_paths(['foo'])
82 self.assertTrue('foo/bar/baz' in model.untracked)
83 self.assertTrue('foo/bar/baz' not in model.staged)
85 def test_revert_paths(self):
86 """Test a simple use of 'revert_paths'."""
87 self.setup_baseline_repo()
88 self.shell('echo change > the-file')
90 model = MainModel(cwd=os.getcwd())
91 model.revert_paths(['the-file'])
93 self.assertTrue('the-file' not in model.staged)
94 self.assertTrue('the-file' not in model.modified)
96 def test_revert_paths_subdir(self):
97 self.setup_baseline_repo()
98 self.shell("""
99 mkdir -p foo/bar &&
100 touch foo/bar/baz &&
101 git add foo/bar/baz &&
102 git commit -m'Changed foo/bar/baz' >/dev/null &&
103 echo change > foo/bar/baz
104 """)
106 model = MainModel(cwd=os.getcwd())
107 model.revert_paths(['foo'])
109 self.assertTrue('foo/bar/baz' not in model.modified)
110 self.assertTrue('foo/bar/baz' not in model.staged)