155
155
file('foo.tmp', 'wt').write('tmp files are ignored')
156
156
self.assertEquals(list(b.unknowns()), [])
157
assert self.capture('unknowns') == ''
157
self.assertEquals(self.capture('unknowns'), '')
159
159
file('foo.c', 'wt').write('int main() {}')
160
160
self.assertEquals(list(b.unknowns()), ['foo.c'])
161
assert self.capture('unknowns') == 'foo.c\n'
161
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
163
163
self.runbzr(['add', 'foo.c'])
164
assert self.capture('unknowns') == ''
164
self.assertEquals(self.capture('unknowns'), '')
166
166
# 'ignore' works when creating the .bzignore file
167
167
file('foo.blah', 'wt').write('blah')
168
168
self.assertEquals(list(b.unknowns()), ['foo.blah'])
169
169
self.runbzr('ignore *.blah')
170
170
self.assertEquals(list(b.unknowns()), [])
171
assert file('.bzrignore', 'rU').read() == '*.blah\n'
171
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
173
173
# 'ignore' works when then .bzrignore file already exists
174
174
file('garh', 'wt').write('garh')
175
175
self.assertEquals(list(b.unknowns()), ['garh'])
176
assert self.capture('unknowns') == 'garh\n'
176
self.assertEquals(self.capture('unknowns'), 'garh\n')
177
177
self.runbzr('ignore garh')
178
178
self.assertEquals(list(b.unknowns()), [])
179
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
179
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
181
181
def test_revert(self):
182
182
self.runbzr('init')
269
269
self.runbzr('export ../latest')
270
270
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
271
271
self.runbzr('export ../first -r 1')
272
assert not os.path.exists('../first/goodbye')
272
self.assert_(not os.path.exists('../first/goodbye'))
273
273
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
274
274
self.runbzr('export ../first.gz -r 1')
275
275
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
276
276
self.runbzr('export ../first.bz2 -r 1')
277
277
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
278
278
self.runbzr('export ../first.tar -r 1')
279
assert os.path.isfile('../first.tar')
279
self.assert_(os.path.isfile('../first.tar'))
280
280
from tarfile import TarFile
281
281
tf = TarFile('../first.tar')
282
assert 'first/hello' in tf.getnames(), tf.getnames()
282
self.assert_('first/hello' in tf.getnames(), tf.getnames())
283
283
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
284
284
self.runbzr('export ../first.tar.gz -r 1')
285
assert os.path.isfile('../first.tar.gz')
285
self.assert_(os.path.isfile('../first.tar.gz'))
286
286
self.runbzr('export ../first.tbz2 -r 1')
287
assert os.path.isfile('../first.tbz2')
287
self.assert_(os.path.isfile('../first.tbz2'))
288
288
self.runbzr('export ../first.tar.bz2 -r 1')
289
assert os.path.isfile('../first.tar.bz2')
289
self.assert_(os.path.isfile('../first.tar.bz2'))
290
290
self.runbzr('export ../first.tar.tbz2 -r 1')
291
assert os.path.isfile('../first.tar.tbz2')
291
self.assert_(os.path.isfile('../first.tar.tbz2'))
292
292
from bz2 import BZ2File
293
293
tf = TarFile('../first.tar.tbz2',
294
294
fileobj=BZ2File('../first.tar.tbz2', 'r'))
295
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
295
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
296
296
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
297
297
self.runbzr('export ../first2.tar -r 1 --root pizza')
298
298
tf = TarFile('../first2.tar')
299
assert 'pizza/hello' in tf.getnames(), tf.getnames()
299
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
301
301
def test_diff(self):
302
302
self.example_branch()
303
303
file('hello', 'wt').write('hello world!')
304
304
self.runbzr('commit -m fixing hello')
305
output = self.runbzr('diff -r 2..3', backtick=1)
305
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
306
306
self.assert_('\n+hello world!' in output)
307
output = self.runbzr('diff -r last:3..last:1', backtick=1)
307
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
308
308
self.assert_('\n+baz' in output)
310
310
def test_diff_branches(self):
690
691
self.create_conflicts()
691
692
self.runbzr('merge ../other --show-base', retcode=1)
692
693
conflict_text = file('hello').read()
693
assert '<<<<<<<' in conflict_text
694
assert '>>>>>>>' in conflict_text
695
assert '=======' in conflict_text
696
assert '|||||||' in conflict_text
697
assert 'hi world' in conflict_text
694
self.assert_('<<<<<<<' in conflict_text)
695
self.assert_('>>>>>>>' in conflict_text)
696
self.assert_('=======' in conflict_text)
697
self.assert_('|||||||' in conflict_text)
698
self.assert_('hi world' in conflict_text)
698
699
self.runbzr('revert')
699
700
self.runbzr('resolve --all')
700
701
self.runbzr('merge ../other', retcode=1)
701
702
conflict_text = file('hello').read()
702
assert '|||||||' not in conflict_text
703
assert 'hi world' not in conflict_text
703
self.assert_('|||||||' not in conflict_text)
704
self.assert_('hi world' not in conflict_text)
704
705
result = self.runbzr('conflicts', backtick=1)
705
706
self.assertEquals(result, "hello\nquestion\n")
706
707
result = self.runbzr('status', backtick=1)
707
assert "conflicts:\n hello\n question\n" in result, result
708
self.assert_("conflicts:\n hello\n question\n" in result, result)
708
709
self.runbzr('resolve hello')
709
710
result = self.runbzr('conflicts', backtick=1)
710
711
self.assertEquals(result, "question\n")
752
753
bzrlib.gpg.GPGStrategy = oldstrategy
756
# create a source branch
757
os.mkdir('my-branch')
758
os.chdir('my-branch')
759
self.example_branch()
761
# with no push target, fail
762
self.runbzr('push', retcode=1)
763
# with an explicit target work
764
self.runbzr('push ../output-branch')
765
# with an implicit target work
768
self.runbzr('missing ../output-branch')
769
# advance this branch
770
self.runbzr('commit --unchanged -m unchanged')
772
os.chdir('../output-branch')
773
# should be a diff as we have not pushed the tree
774
self.runbzr('diff', retcode=1)
775
self.runbzr('revert')
778
# diverge the branches
779
self.runbzr('commit --unchanged -m unchanged')
780
os.chdir('../my-branch')
782
self.runbzr('push', retcode=1)
783
# and there are difference
784
self.runbzr('missing ../output-branch', retcode=1)
785
# but we can force a push
786
self.runbzr('push --overwrite')
788
self.runbzr('missing ../output-branch')
790
# pushing to a new dir with no parent should fail
791
self.runbzr('push ../missing/new-branch', retcode=1)
792
# unless we provide --create-prefix
793
self.runbzr('push --create-prefix ../missing/new-branch')
795
self.runbzr('missing ../missing/new-branch')
755
798
def listdir_sorted(dir):
756
799
L = os.listdir(dir)
786
829
self.assertEquals(capture('unknowns'), 'test.txt\n')
788
831
out = capture("status")
789
assert out == 'unknown:\n test.txt\n'
832
self.assertEquals(out, 'unknown:\n test.txt\n')
791
834
out = capture("status --all")
792
assert out == "unknown:\n test.txt\n"
835
self.assertEquals(out, "unknown:\n test.txt\n")
794
837
out = capture("status test.txt --all")
795
assert out == "unknown:\n test.txt\n"
838
self.assertEquals(out, "unknown:\n test.txt\n")
797
840
f = file('test2.txt', 'wt')
798
841
f.write('goodbye cruel world...\n')
801
844
out = capture("status test.txt")
802
assert out == "unknown:\n test.txt\n"
845
self.assertEquals(out, "unknown:\n test.txt\n")
804
847
out = capture("status")
805
assert out == ("unknown:\n"
848
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
809
850
os.unlink('test2.txt')
811
852
progress("command aliases")
812
853
out = capture("st --all")
813
assert out == ("unknown:\n"
854
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
816
856
out = capture("stat")
817
assert out == ("unknown:\n"
857
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
820
859
progress("command help")
821
860
runbzr("help st")
858
896
self.assertEqual(capture("relpath sub2/hello.txt"),
859
897
os.path.join("sub2", "hello.txt\n"))
861
assert exists("sub2")
862
assert exists("sub2/hello.txt")
863
assert not exists("sub1")
864
assert not exists("hello.txt")
899
self.assert_(exists("sub2"))
900
self.assert_(exists("sub2/hello.txt"))
901
self.assert_(not exists("sub1"))
902
self.assert_(not exists("hello.txt"))
866
904
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
869
907
runbzr('add sub1')
870
908
runbzr('move sub2/hello.txt sub1')
871
assert not exists('sub2/hello.txt')
872
assert exists('sub1/hello.txt')
909
self.assert_(not exists('sub2/hello.txt'))
910
self.assert_(exists('sub1/hello.txt'))
873
911
runbzr('move sub2 sub1')
874
assert not exists('sub2')
875
assert exists('sub1/sub2')
912
self.assert_(not exists('sub2'))
913
self.assert_(exists('sub1/sub2'))
877
915
runbzr(['commit', '-m', 'rename nested subdirectories'])
880
918
self.assertEquals(capture('root')[:-1],
881
919
os.path.join(self.test_dir, 'branch1'))
882
920
runbzr('move ../hello.txt .')
883
assert exists('./hello.txt')
921
self.assert_(exists('./hello.txt'))
884
922
self.assertEquals(capture('relpath hello.txt'),
885
923
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
886
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
924
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
887
925
runbzr(['commit', '-m', 'move to parent directory'])
889
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
927
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
891
929
runbzr('move sub2/hello.txt .')
892
assert exists('hello.txt')
930
self.assert_(exists('hello.txt'))
894
932
f = file('hello.txt', 'wt')
895
933
f.write('some nice new content\n')
910
948
runbzr('log -v --forward')
911
949
runbzr('log -m', retcode=1)
912
950
log_out = capture('log -m commit')
913
assert "this is my new commit\n and" in log_out
914
assert "rename nested" not in log_out
915
assert 'revision-id' not in log_out
916
assert 'revision-id' in capture('log --show-ids -m commit')
951
self.assert_("this is my new commit\n and" in log_out)
952
self.assert_("rename nested" not in log_out)
953
self.assert_('revision-id' not in log_out)
954
self.assert_('revision-id' in capture('log --show-ids -m commit'))
918
956
log_out = capture('log --line')
919
957
for line in log_out.splitlines():
920
assert len(line) <= 79, len(line)
921
assert "this is my new commit and" in log_out
958
self.assert_(len(line) <= 79, len(line))
959
self.assert_("this is my new commit and" in log_out)
924
962
progress("file with spaces in name")
925
963
mkdir('sub directory')
926
964
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
966
runbzr('diff', retcode=1)
929
967
runbzr('commit -m add-spaces')
942
980
os.symlink("NOWHERE1", "link1")
943
981
runbzr('add link1')
944
assert self.capture('unknowns') == ''
982
self.assertEquals(self.capture('unknowns'), '')
945
983
runbzr(['commit', '-m', '1: added symlink link1'])
949
assert self.capture('unknowns') == ''
987
self.assertEquals(self.capture('unknowns'), '')
950
988
os.symlink("NOWHERE2", "d1/link2")
951
assert self.capture('unknowns') == 'd1/link2\n'
989
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
952
990
# is d1/link2 found when adding d1
954
assert self.capture('unknowns') == ''
992
self.assertEquals(self.capture('unknowns'), '')
955
993
os.symlink("NOWHERE3", "d1/link3")
956
assert self.capture('unknowns') == 'd1/link3\n'
994
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
957
995
runbzr(['commit', '-m', '2: added dir, symlink'])
959
997
runbzr('rename d1 d2')
960
998
runbzr('move d2/link2 .')
961
999
runbzr('move link1 d2')
962
assert os.readlink("./link2") == "NOWHERE2"
963
assert os.readlink("d2/link1") == "NOWHERE1"
1000
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1001
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
964
1002
runbzr('add d2/link3')
1003
runbzr('diff', retcode=1)
966
1004
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
968
1006
os.unlink("link2")
969
1007
os.symlink("TARGET 2", "link2")
970
1008
os.unlink("d2/link1")
971
1009
os.symlink("TARGET 1", "d2/link1")
973
assert self.capture("relpath d2/link1") == "d2/link1\n"
1010
runbzr('diff', retcode=1)
1011
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
974
1012
runbzr(['commit', '-m', '4: retarget of two links'])
976
1014
runbzr('remove d2/link1')
977
assert self.capture('unknowns') == 'd2/link1\n'
1015
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
978
1016
runbzr(['commit', '-m', '5: remove d2/link1'])
979
1017
# try with the rm alias
980
1018
runbzr('add d2/link1')
981
1019
runbzr(['commit', '-m', '6: add d2/link1'])
982
1020
runbzr('rm d2/link1')
983
assert self.capture('unknowns') == 'd2/link1\n'
1021
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
984
1022
runbzr(['commit', '-m', '7: remove d2/link1'])
987
1025
runbzr('add d1')
988
1026
runbzr('rename d2/link3 d1/link3new')
989
assert self.capture('unknowns') == 'd2/link1\n'
1027
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
990
1028
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
992
1030
runbzr(['check'])
994
1032
runbzr(['export', '-r', '1', 'exp1.tmp'])
995
1033
chdir("exp1.tmp")
996
assert listdir_sorted(".") == [ "link1" ]
997
assert os.readlink("link1") == "NOWHERE1"
1034
self.assertEquals(listdir_sorted("."), [ "link1" ])
1035
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1000
1038
runbzr(['export', '-r', '2', 'exp2.tmp'])
1001
1039
chdir("exp2.tmp")
1002
assert listdir_sorted(".") == [ "d1", "link1" ]
1040
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1005
1043
runbzr(['export', '-r', '3', 'exp3.tmp'])
1006
1044
chdir("exp3.tmp")
1007
assert listdir_sorted(".") == [ "d2", "link2" ]
1008
assert listdir_sorted("d2") == [ "link1", "link3" ]
1009
assert os.readlink("d2/link1") == "NOWHERE1"
1010
assert os.readlink("link2") == "NOWHERE2"
1045
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1046
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1047
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1048
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1013
1051
runbzr(['export', '-r', '4', 'exp4.tmp'])
1014
1052
chdir("exp4.tmp")
1015
assert listdir_sorted(".") == [ "d2", "link2" ]
1016
assert os.readlink("d2/link1") == "TARGET 1"
1017
assert os.readlink("link2") == "TARGET 2"
1018
assert listdir_sorted("d2") == [ "link1", "link3" ]
1053
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1054
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1055
self.assertEquals(os.readlink("link2") , "TARGET 2")
1056
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1021
1059
runbzr(['export', '-r', '5', 'exp5.tmp'])
1022
1060
chdir("exp5.tmp")
1023
assert listdir_sorted(".") == [ "d2", "link2" ]
1024
assert os.path.islink("link2")
1025
assert listdir_sorted("d2")== [ "link3" ]
1061
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1062
self.assert_(os.path.islink("link2"))
1063
self.assert_(listdir_sorted("d2")== [ "link3" ])
1028
1066
runbzr(['export', '-r', '8', 'exp6.tmp'])
1029
1067
chdir("exp6.tmp")
1030
1068
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1031
assert listdir_sorted("d1") == [ "link3new" ]
1032
assert listdir_sorted("d2") == []
1033
assert os.readlink("d1/link3new") == "NOWHERE3"
1069
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1070
self.assertEquals(listdir_sorted("d2"), [])
1071
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1036
1074
progress("skipping symlink tests")