def test_simple(self): [c1] = build_commit_graph(self.repo.object_store, [[1]]) self.repo[b"HEAD"] = c1.id porcelain.tag_create(self.repo, b'foo') self.assertTrue(b"foo" in porcelain.tag_list(self.repo)) porcelain.tag_delete(self.repo, b'foo') self.assertFalse(b"foo" in porcelain.tag_list(self.repo))
def listVersion(self, regexs): repo = Repo(self.target) tags = tag_list(repo) result = [] for tag in tags: tag = tag.decode('utf-8') for rex in regexs: if (re.match(rex, tag)): result.append(tag) result=list(set(result)) result.sort(key=LooseVersion) result.extend(self.branches) return result
def determine_version(repo): """Determines the correct next version""" tags = [x.decode('utf-8') for x in tag_list(repo)] tags.sort(key=lambda s: [int(u) for u in s.split('.')]) today = date.today() this_year = str(today.year)[2:] # ignore the millennium index = 0 if tags: year, month, index = tags[-1].split('.') if year == this_year: if month == str(today.month): index = int(index) + 1 return f'{this_year}.{today.month}.{index}'
def get_version() -> str: """ Return the next version. This is today’s date in the format ``YYYY.MM.DD.MICRO``. ``MICRO`` refers to the number of releases created on this date, starting from ``0``. """ utc_now = datetime.datetime.utcnow() date_format = '%Y.%m.%d' date_str = utc_now.strftime(date_format) local_repository = Repo('.') tag_labels = tag_list(repo=local_repository) tag_labels = [item.decode() for item in tag_labels] today_tag_labels = [ item for item in tag_labels if item.startswith(date_str) ] micro = int(len(today_tag_labels)) return '{date}.{micro}'.format(date=date_str, micro=micro)
def existing_tags(git): versions = list(v.decode("utf8") for v in tag_list(git)) return versions
def test_simple(self): self.repo.refs[b"refs/tags/foo"] = b"aa" * 20 self.repo.refs[b"refs/tags/bar/bla"] = b"bb" * 20 tags = porcelain.tag_list(self.repo.path) self.assertEqual([b"bar/bla", b"foo"], tags)
def test_empty(self): tags = porcelain.tag_list(self.repo.path) self.assertEqual([], tags)
def git_tag_list(repo_path: str) -> List[str]: """ Lists git tags on a cloned repo """ porcelain.tag_list(repo_path)
def testDulwich(self): # init remote and repo dir remote = os.path.join(self.wdir, 'git_remote') if os.path.exists(remote): del_tree(remote) os.mkdir(remote) path = os.path.join(self.wdir, 'git_test') if os.path.exists(path): del_tree(path) os.mkdir(path) # start at remote self.assertReturnsNonZero(status_git, path=remote) self.assertReturnsZero(init_git, path=remote) first_file = 'first_file' first_contents = 'Hello to repo!' with open(os.path.join(remote, first_file), 'w') as file: file.write(first_contents) self.assertIn(first_file, status(remote).untracked) self.assertReturnsZero(add_git, path=remote) self.assertIn(first_file.encode(), status(remote).staged['add']) self.assertReturnsZero(add_and_commit_git, 'remote_commit', path=remote) self.assertReturnsZero(branch_git, 'other', path=remote) if os.name == 'posix': self.assertReturnsZero(checkout_git, 'other', path=remote) # switch to repo self.assertReturnsZero(clone_git, remote, path=path) if os.name == 'posix': self.assertReturnsZero(checkout_git, 'master', path=path) self.assertReturnsZero(pull_git, remote, path=path) self.assertReturnsZero(add_and_commit_git, 'empty_commit', path=path) with open(os.path.join(path, 'first_file'), 'r') as file: read_first_contents = file.read() self.assertEqual(first_contents, read_first_contents) append_contents = ' And hello to remote!' with open(os.path.join(path, first_file), 'a') as file: file.write(append_contents) second_contents = 'Hello to remote!' second_file = 'second_file' with open(os.path.join(path, second_file), 'w') as file: file.write(second_contents) self.assertIn(first_file.encode(), status(path).unstaged) self.assertIn(second_file, status(path).untracked) self.assertReturnsZero(status_git, path=path) self.assertReturnsZero(add_git, path=path) self.assertReturnsZero(status_git, path=path) self.assertIn(first_file.encode(), status(path).staged['modify']) self.assertIn(second_file.encode(), status(path).staged['add']) self.assertReturnsZero(add_and_commit_git, 'repo_commit', path=path) tag = 'test_tag' self.assertReturnsZero(tag_git, tag, path=path) self.assertIn(tag.encode(), tag_list(path)) self.assertReturnsZero(push_git, remote, path=path) # switch back to remote if os.name == 'posix': self.assertReturnsZero(checkout_git, 'master', path=remote) with open(os.path.join(remote, first_file), 'r') as file: self.assertEqual(file.read(), first_contents + append_contents) with open(os.path.join(remote, second_file), 'r') as file: self.assertEqual(file.read(), second_contents)