本文整理汇总了Python中git.Repo.create_tag方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.create_tag方法的具体用法?Python Repo.create_tag怎么用?Python Repo.create_tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Repo
的用法示例。
在下文中一共展示了Repo.create_tag方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _git_tag
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
def _git_tag(version):
"""
Tags the latest commit with the new version
"""
if confirm('Tag latest commit to repo?'):
repo = Repo(os.path.dirname(os.path.abspath(__file__)))
commit = repo.head.commit
repo.create_tag(version, ref=commit)
示例2: do_release
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
def do_release(self, line):
repo = Repo('.')
tags = repo.tags
tag_name = raw_input("Please Enter a tag name to Create:")
new_tag = tag_name
if new_tag not in tags:
repo.create_tag(new_tag, message='V2.0')
repo.git.push(tags=True)
else:
print "Tag already exists with the same name"
"""Deleting tags"""
示例3: make_tag
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
def make_tag(ctx, version):
"""Create a new, local tag for the release, only if the repository is clean."""
from git import Repo
repo = Repo('.')
if repo.is_dirty():
print('Current repository is dirty. Please commit any changes and try again.')
raise invoke.Exit(code=2)
tag_names = [x.name for x in repo.tags]
if version in tag_names:
print("[generate.make_tag] Delete existing tag {}".format(version))
repo.delete_tag(version)
print("[generate.make_tag] Create tag {}".format(version))
repo.create_tag(version)
示例4: release
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
def release(project_name, project_dir, tmp_dir, release_version, next_dev_version, pypi_servers, **extra_config):
# Update changelog and version
changelog_path = project_dir /'CHANGES.rst'
version_path = project_dir / 'src' / project_name / '__init__.py'
new_changelog = update_changelog(changelog_path, dest_dir=tmp_dir, version=release_version)
new_version = update_version_file(original=version_path, project_name=project_name,
dest_dir=tmp_dir, version=release_version)
shutil.copyfile(new_changelog, changelog_path.as_posix())
shutil.copyfile(new_version, version_path.as_posix())
# Create relase commit and tag
repo = Repo(project_dir.as_posix())
paths = [p.as_posix() for p in (changelog_path, version_path)]
repo.index.add(paths)
repo.index.commit('Release {}'.format(release_version))
repo.create_tag(release_version, message='Tagging {}'.format(release_version))
# Post-release, back to development
new_changelog = update_changelog(changelog_path, dest_dir=tmp_dir,
version=get_next_version(next_dev_version), release=False)
new_version = update_version_file(original=version_path, project_name=project_name,
dest_dir=tmp_dir, version=next_dev_version)
shutil.copyfile(new_changelog, changelog_path.as_posix())
shutil.copyfile(new_version, version_path.as_posix())
repo.index.add(paths)
repo.index.commit('Back to development')
if extra_config['git_push']:
git_push(repo, release_version)
pypi = extra_config['upload_to_pypi'].lower()
if pypi != 'nope':
pypi_servers = {k.lower(): v for k ,v in pypi_servers.items()}
with checkout_tag(repo, release_version):
pypi_upload(pypi_conf=pypi_servers[pypi])
示例5: VersionedRepo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
class VersionedRepo (object):
""" Representation of a git repo that follows our versioning rules """
def __init__(self, repo_root):
self.log = logging.getLogger("VersionedRepo")
self.repo = Repo(repo_root, search_parent_directories=True)
self.is_dirty = self.repo.is_dirty()
self.branches = {}
def get_branch(self, branch_name):
# Grab a branch of this repo
key = branch_name if branch_name else '*current*'
source = 'cache'
vbr = None
if key in self.branches:
vbr = self.branches[key]
if not vbr:
source = 'Git'
head = None
if branch_name:
print(self.repo.heads)
head = self.repo.heads[branch_name]
else:
# head = self.repo.active_branch
head = self.repo.head
if not head:
self.log.warning("get_branch: no branch %s" % branch_name)
vbr = VersionedBranch(self.repo, head)
self.branches[key] = vbr
self.log.debug("get_branch: got %s from %s" % (key, source))
return vbr
def tag_version(self, version, commit):
tag_name = str(version)
new_tag = self.repo.create_tag(tag_name, commit)
return new_tag
示例6: finish_release
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
def finish_release(branch):
version = branch.replace("release/", "")
repo = Repo(get_project_root())
remote = repo.remotes["origin"]
if repo.is_dirty() == True:
print "The working tree contains uncommitted changes, commit or stash "
print "these and try again."
return 1
print "Summary of actions:"
stable = repo.heads.stable
stable.checkout()
repo.git.merge(branch, '--no-ff')
print ("- Branch " + branch + " was merged into stable.")
tag = repo.create_tag(version)
print ("- A release tag " + version + " was created.")
remote.push(tag)
print ("- Tag " + version + " was pushed to origin.")
master = repo.heads.master
master.checkout()
repo.git.merge(branch, '--no-ff')
print ("- Branch " + branch + " was merged into master.")
remote.push(master)
print ("- Merged changes on master were pushed to origin.")
remote.push(stable)
print ("- Merged changes on stable were pushed to origin.")
repo.delete_head(branch, force=True)
print ("- Branch " + branch + " was deleted.")
ret = remote.push(":" + branch)
print ("- Remote branch " + branch + " on origin was deleted.")
print "- You are now on branch master."
print ""
return 0
示例7: tag
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
def tag(self, tag, description):
repo = Repo(self.path)
repo.create_tag(tag, message=description)
remote = repo.remote()
remote.push('refs/tags/%s:refs/tags/%s' % (tag, tag))
示例8: __init__
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
class ReleaseContext:
def __init__(
self,
release_type,
cargo_file,
version_file,
readme_file,
disable_checks,
dry_run
):
# Either final or snapshot
self.release_type = release_type.lower()
# This should be the path to the Cargo.toml file.
self.cargo_file = cargo_file
# This should be the path to the version.txt file.
self.version_file = version_file
# This should be the path to the README.md file.
self.readme_file = readme_file
# disable_checks is useful for testing of the release script.
# It should not be used normally.
self.disable_checks = disable_checks
# Do everything non destructively. That is, the script will run with
# output but nothing will actually be committed.
self.dry_run = dry_run
# The git repo.
self._repo = Repo('.')
def repo_active_branch(self):
return self._repo.active_branch.name
def repo_is_dirty(self):
return self._repo.is_dirty()
def commit_release(self, message):
self._repo.git.add(update=True)
self._repo.index.commit(message)
def tag_release(self, tag, tag_message):
self._repo.create_tag(tag, message=tag_message)
def push_to_origin(self):
self._repo.remotes.origin.push('refs/heads/*:refs/heads/*', tags=True)
def is_snapshot_release(self):
return self.release_type == RELEASE_TYPE_SNAPSHOT
def is_final_release(self):
return self.release_type == RELEASE_TYPE_FINAL
def is_test_final_release(self):
return self.release_type == RELEASE_TYPE_TEST_FINAL
def checkout_master(self):
self._repo.heads.master.checkout()
def checkout_test_master(self):
self._repo.heads.testmaster.checkout()
def checkout_develop(self):
self._repo.heads.develop.checkout()
def merge_develop(self):
self._repo.git.merge(BRANCH_DEVELOP)
示例9: GitFlow
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
#.........这里部分代码省略.........
elif base == commit2:
return 2
else:
return 3
@requires_repo
def require_branches_equal(self, branch1, branch2):
status = self._compare_branches(branch1, branch2)
if status == 0:
# branches are equal
return
else:
warn("Branches '%s' and '%s' have diverged." % (branch1, branch2))
if status == 1:
raise SystemExit("And branch '%s' may be fast-forwarded." % branch1)
elif status == 2:
# Warn here, since there is no harm in being ahead
warn("And local branch '%s' is ahead of '%s'." % (branch1, branch2))
else:
raise SystemExit("Branches need merging first.")
@requires_repo
def start_transaction(self, message=None):
if message:
info(message)
@requires_initialized
def tag(self, tagname, commit, message=None, sign=False, signingkey=None):
kwargs = {}
if sign:
kwargs['s'] = True
if signingkey:
kwargs['u'] = signingkey
self.repo.create_tag(tagname, commit, message=message or None, **kwargs)
#
# ====== sub commands =====
#
@requires_repo
def list(self, identifier, arg0_name, verbose, use_tagname):
"""
List the all branches of the given type. If there are not
branches of this type, raises :exc:`Usage` with an
explanation on how to start a branch of this type.
:param identifier:
The identifier for the type of branch to work on.
A :class:`BranchManager <git.branches.BranchManager>` for the given
identifier must exist in the :attr:`self.managers`.
:param arg0_name:
Name of the first argument for the command line to be put
into the explanation on how to start a branch of this
type. This typically is `name` or `version`.
:param verbose:
If True, give more information about the state of the
branch: Whether it's ahead or behind it's default base,
may be rebased, etc.
:param use_tagname:
If True, try to describe the state based on the next tag.
"""
repo = self.repo
manager = self.managers[identifier]
示例10: NoRevision
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import create_tag [as 别名]
class DataStorageManager:
FIRST_REV_NUMBER = 0
__revision_tag_name = 'rev-{}'
class NoRevision(Exception):
pass
class NoFile(Exception):
pass
def __init__(self, store_name):
self.store_name = store_name
self.store_storage_dir = os.path.join(settings.ST_STORES_DATA_DIR, store_name)
os.makedirs(self.store_storage_dir, exist_ok=True)
if not os.path.exists(os.path.join(self.store_storage_dir, '.git/')):
self.repo = Repo.init(self.store_storage_dir)
else:
self.repo = Repo(self.store_storage_dir)
self.__asert_is_clean()
@contextmanager
def save(self, filename):
self.__asert_is_clean()
file_path = os.path.join(self.store_storage_dir, filename)
file = open(file_path, 'wb')
yield file
file.close()
self.repo.index.add([file_path])
commit_date = datetime.now()
commit_datetime_str = commit_date.strftime("%Y-%m-%d %H:%M:%S")
commit_msg = "Store: {}\nDate: {}".format(self.store_name, commit_datetime_str)
self.repo.index.commit(commit_msg)
self.__increment_revision()
def get(self, filename, revision=None):
self.__asert_is_clean()
try:
revision = revision or self.last_revision_number()
self.repo.git.checkout(self.__revision_tag_name.format(revision))
except (GitCommandError, DataStorageManager.NoRevision):
raise DataStorageManager.NoRevision()
file_path = os.path.join(self.store_storage_dir, filename)
if not os.path.exists(file_path):
raise DataStorageManager.NoFile()
with open(file_path) as f:
content = f.read()
self.repo.git.checkout('master')
return content
def __asert_is_clean(self):
assert not self.repo.is_dirty(), "Repository '{}' is dirty. " \
"Has to be cleaned up before further work.".format(self.store_storage_dir)
def __increment_revision(self):
try:
next_rev = self.last_revision_number() + 1
except DataStorageManager.NoRevision:
next_rev = 0
self.repo.create_tag(self.__revision_tag_name.format(next_rev))
def last_revision_number(self):
self.__asert_is_clean()
try:
return max([
int(tag.name.replace(self.__revision_tag_name.format(''), ''))
for tag in self.repo.tags
if tag.name.startswith(self.__revision_tag_name.format(''))
])
except ValueError:
raise DataStorageManager.NoRevision()