... |
... |
@@ -883,6 +883,194 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type): |
883
|
883
|
assert p.returncode != 0
|
884
|
884
|
|
885
|
885
|
|
|
886
|
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
|
|
887
|
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
|
|
888
|
+@pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')])
|
|
889
|
+@pytest.mark.parametrize("tag_type", [('annotated'), ('lightweight')])
|
|
890
|
+def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_type):
|
|
891
|
+ project = str(datafiles)
|
|
892
|
+
|
|
893
|
+ project_config = _yaml.load(os.path.join(project, 'project.conf'))
|
|
894
|
+ project_config['ref-storage'] = ref_storage
|
|
895
|
+ _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
|
|
896
|
+
|
|
897
|
+ repofiles = os.path.join(str(tmpdir), 'repofiles')
|
|
898
|
+ os.makedirs(repofiles, exist_ok=True)
|
|
899
|
+ file0 = os.path.join(repofiles, 'file0')
|
|
900
|
+ with open(file0, 'w') as f:
|
|
901
|
+ f.write('test\n')
|
|
902
|
+
|
|
903
|
+ repo = create_repo('git', str(tmpdir))
|
|
904
|
+
|
|
905
|
+ def tag(name):
|
|
906
|
+ if tag_type == 'annotated':
|
|
907
|
+ repo.add_annotated_tag(name, name)
|
|
908
|
+ else:
|
|
909
|
+ repo.add_tag(name)
|
|
910
|
+
|
|
911
|
+ ref = repo.create(repofiles)
|
|
912
|
+ tag('uselesstag')
|
|
913
|
+
|
|
914
|
+ file1 = os.path.join(str(tmpdir), 'file1')
|
|
915
|
+ with open(file1, 'w') as f:
|
|
916
|
+ f.write('test\n')
|
|
917
|
+ repo.add_file(file1)
|
|
918
|
+
|
|
919
|
+ file2 = os.path.join(str(tmpdir), 'file2')
|
|
920
|
+ with open(file2, 'w') as f:
|
|
921
|
+ f.write('test\n')
|
|
922
|
+ repo.branch('branch2')
|
|
923
|
+ repo.add_file(file2)
|
|
924
|
+
|
|
925
|
+ repo.checkout('master')
|
|
926
|
+ file3 = os.path.join(str(tmpdir), 'file3')
|
|
927
|
+ with open(file3, 'w') as f:
|
|
928
|
+ f.write('test\n')
|
|
929
|
+ repo.add_file(file3)
|
|
930
|
+
|
|
931
|
+ tagged_ref = repo.merge('branch2')
|
|
932
|
+ tag('tag')
|
|
933
|
+
|
|
934
|
+ config = repo.source_config()
|
|
935
|
+ config['track'] = repo.latest_commit()
|
|
936
|
+ config['track-tags'] = True
|
|
937
|
+
|
|
938
|
+ # Write out our test target
|
|
939
|
+ element = {
|
|
940
|
+ 'kind': 'import',
|
|
941
|
+ 'sources': [
|
|
942
|
+ config
|
|
943
|
+ ],
|
|
944
|
+ }
|
|
945
|
+ element_path = os.path.join(project, 'target.bst')
|
|
946
|
+ _yaml.dump(element, element_path)
|
|
947
|
+
|
|
948
|
+ if ref_storage == 'inline':
|
|
949
|
+ result = cli.run(project=project, args=['source', 'track', 'target.bst'])
|
|
950
|
+ result.assert_success()
|
|
951
|
+ else:
|
|
952
|
+ result = cli.run(project=project, args=['source', 'track', 'target.bst', '--deps', 'all'])
|
|
953
|
+ result.assert_success()
|
|
954
|
+
|
|
955
|
+ if ref_storage == 'inline':
|
|
956
|
+ element = _yaml.load(element_path)
|
|
957
|
+ tags = _yaml.node_sanitize(element['sources'][0]['tags'])
|
|
958
|
+ assert len(tags) == 1
|
|
959
|
+ for tag in tags:
|
|
960
|
+ assert 'tag' in tag
|
|
961
|
+ assert 'commit' in tag
|
|
962
|
+ assert 'annotated' in tag
|
|
963
|
+ assert tag['annotated'] == (tag_type == 'annotated')
|
|
964
|
+
|
|
965
|
+ assert set([(tag['tag'], tag['commit']) for tag in tags]) == set([('tag', repo.rev_parse('tag^{commit}'))])
|
|
966
|
+
|
|
967
|
+ checkout = os.path.join(str(tmpdir), 'checkout')
|
|
968
|
+
|
|
969
|
+ result = cli.run(project=project, args=['build', 'target.bst'])
|
|
970
|
+ result.assert_success()
|
|
971
|
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkout])
|
|
972
|
+ result.assert_success()
|
|
973
|
+
|
|
974
|
+ if tag_type == 'annotated':
|
|
975
|
+ options = []
|
|
976
|
+ else:
|
|
977
|
+ options = ['--tags']
|
|
978
|
+ describe = subprocess.check_output(['git', 'describe'] + options,
|
|
979
|
+ cwd=checkout).decode('ascii')
|
|
980
|
+ assert describe.startswith('tag')
|
|
981
|
+
|
|
982
|
+ tags = subprocess.check_output(['git', 'tag'],
|
|
983
|
+ cwd=checkout).decode('ascii')
|
|
984
|
+ tags = set(tags.splitlines())
|
|
985
|
+ assert tags == set(['tag'])
|
|
986
|
+
|
|
987
|
+ rev_list = subprocess.check_output(['git', 'rev-list', '--all'],
|
|
988
|
+ cwd=checkout).decode('ascii')
|
|
989
|
+
|
|
990
|
+ assert set(rev_list.splitlines()) == set([tagged_ref])
|
|
991
|
+
|
|
992
|
+ p = subprocess.run(['git', 'log', repo.rev_parse('uselesstag')],
|
|
993
|
+ cwd=checkout)
|
|
994
|
+ assert p.returncode != 0
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
|
|
998
|
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
|
|
999
|
+def test_git_describe_relevant_history(cli, tmpdir, datafiles):
|
|
1000
|
+ project = str(datafiles)
|
|
1001
|
+
|
|
1002
|
+ project_config = _yaml.load(os.path.join(project, 'project.conf'))
|
|
1003
|
+ project_config['ref-storage'] = 'project.refs'
|
|
1004
|
+ _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
|
|
1005
|
+
|
|
1006
|
+ repofiles = os.path.join(str(tmpdir), 'repofiles')
|
|
1007
|
+ os.makedirs(repofiles, exist_ok=True)
|
|
1008
|
+ file0 = os.path.join(repofiles, 'file0')
|
|
1009
|
+ with open(file0, 'w') as f:
|
|
1010
|
+ f.write('test\n')
|
|
1011
|
+
|
|
1012
|
+ repo = create_repo('git', str(tmpdir))
|
|
1013
|
+
|
|
1014
|
+ file1 = os.path.join(str(tmpdir), 'file1')
|
|
1015
|
+ with open(file1, 'w') as f:
|
|
1016
|
+ f.write('test\n')
|
|
1017
|
+ repo.add_file(file1)
|
|
1018
|
+ repo.branch('branch')
|
|
1019
|
+ repo.checkout('master')
|
|
1020
|
+
|
|
1021
|
+ file2 = os.path.join(str(tmpdir), 'file2')
|
|
1022
|
+ with open(file2, 'w') as f:
|
|
1023
|
+ f.write('test\n')
|
|
1024
|
+ repo.add_file(file2)
|
|
1025
|
+
|
|
1026
|
+ file3 = os.path.join(str(tmpdir), 'file3')
|
|
1027
|
+ with open(file3, 'w') as f:
|
|
1028
|
+ f.write('test\n')
|
|
1029
|
+ branch_boundary = repo.add_file(file3)
|
|
1030
|
+
|
|
1031
|
+ repo.checkout('branch')
|
|
1032
|
+ file4 = os.path.join(str(tmpdir), 'file4')
|
|
1033
|
+ with open(file4, 'w') as f:
|
|
1034
|
+ f.write('test\n')
|
|
1035
|
+ tagged_ref = repo.add_file(file4)
|
|
1036
|
+ repo.add_annotated_tag('tag1', 'tag1')
|
|
1037
|
+
|
|
1038
|
+ head = repo.merge('master')
|
|
1039
|
+
|
|
1040
|
+ config = repo.source_config()
|
|
1041
|
+ config['track'] = head
|
|
1042
|
+ config['track-tags'] = True
|
|
1043
|
+
|
|
1044
|
+ # Write out our test target
|
|
1045
|
+ element = {
|
|
1046
|
+ 'kind': 'import',
|
|
1047
|
+ 'sources': [
|
|
1048
|
+ config
|
|
1049
|
+ ],
|
|
1050
|
+ }
|
|
1051
|
+ element_path = os.path.join(project, 'target.bst')
|
|
1052
|
+ _yaml.dump(element, element_path)
|
|
1053
|
+
|
|
1054
|
+ result = cli.run(project=project, args=['source', 'track', 'target.bst', '--deps', 'all'])
|
|
1055
|
+ result.assert_success()
|
|
1056
|
+
|
|
1057
|
+ checkout = os.path.join(str(tmpdir), 'checkout')
|
|
1058
|
+
|
|
1059
|
+ result = cli.run(project=project, args=['build', 'target.bst'])
|
|
1060
|
+ result.assert_success()
|
|
1061
|
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkout])
|
|
1062
|
+ result.assert_success()
|
|
1063
|
+
|
|
1064
|
+ describe = subprocess.check_output(['git', 'describe'],
|
|
1065
|
+ cwd=checkout).decode('ascii')
|
|
1066
|
+ assert describe.startswith('tag1-2-')
|
|
1067
|
+
|
|
1068
|
+ rev_list = subprocess.check_output(['git', 'rev-list', '--all'],
|
|
1069
|
+ cwd=checkout).decode('ascii')
|
|
1070
|
+
|
|
1071
|
+ assert set(rev_list.splitlines()) == set([head, tagged_ref, branch_boundary])
|
|
1072
|
+
|
|
1073
|
+
|
886
|
1074
|
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
|
887
|
1075
|
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
|
888
|
1076
|
def test_default_do_not_track_tags(cli, tmpdir, datafiles):
|