本文整理汇总了Python中git.Git.config方法的典型用法代码示例。如果您正苦于以下问题:Python Git.config方法的具体用法?Python Git.config怎么用?Python Git.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.config方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_credentials
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import config [as 别名]
def get_credentials(cls, repo=None):
"""
Get credentials from the github.user and github.token config values
"""
if repo:
_git = repo.git
else:
_git = Git(os.getcwd())
return cls(
user=_git.config("github.user", with_exceptions=False),
token=_git.config("github.token", with_exceptions=False),
)
示例2: get_credentials
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import config [as 别名]
def get_credentials(cls, repo=None):
"""
Get credentials from the github.user and github.token config values
"""
if repo:
_git = repo.git
else:
_git = Git(os.getcwd())
return cls(
user=_git.config('github.user'),
token=_git.config('github.token')
)
示例3: GitWrapper
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import config [as 别名]
#.........这里部分代码省略.........
cmd.wait()
except GitCommandError as error:
# Add more meta-information to errors
message = "'{0}' returned exit status {1}".format(
' '.join(str(c) for c in error.command),
error.status
)
raise GitError(message, stderr=error.stderr, stdout=stdout)
return stdout.strip()
def __getattr__(self, name):
return lambda *args, **kwargs: self.run(name, *args, **kwargs)
###########################################################################
# Overwrite some methods and add new ones
###########################################################################
@contextmanager
def stash(self):
"""
A stashing contextmanager.
It stashes all changes inside and unstashed when done.
"""
stashed = False
if self.repo.is_dirty(submodules=False):
if self.change_count > 1:
message = 'stashing {0} changes'
else:
message = 'stashing {0} change'
print(colored(
message.format(self.change_count),
'magenta'
))
self.git.stash()
stashed = True
yield
if stashed:
print(colored('unstashing', 'magenta'))
try:
self.run('stash', 'pop')
except GitError as e:
raise UnstashError(stderr=e.stderr, stdout=e.stdout)
def checkout(self, branch_name):
""" Checkout a branch by name. """
try:
find(
self.repo.branches, lambda b: b.name == branch_name
).checkout()
except OrigCheckoutError as e:
raise CheckoutError(branch_name, details=e)
def rebase(self, target_branch):
""" Rebase to target branch. """
current_branch = self.repo.active_branch
arguments = (
([self.config('git-up.rebase.arguments')] or []) +
[target_branch.name]
)
try:
self.run('rebase', *arguments)
except GitError as e:
raise RebaseError(current_branch.name, target_branch.name,
**e.__dict__)
def config(self, key):
""" Return `git config key` output or None. """
try:
return self.git.config(key)
except GitCommandError:
return None
@property
def change_count(self):
""" The number of changes in the working directory. """
status = self.git.status(porcelain=True, untracked_files='no').strip()
if not status:
return 0
else:
return len(status.split('\n'))
@property
def version(self):
"""
Return git's version as a list of numbers.
The original repo.git.version_info has problems with tome types of
git version strings.
"""
return re.search(r'\d+(\.\d+)+', self.git.version()).group(0)
def is_version_min(self, required_version):
""" Does git's version match the requirements? """
return self.version.split('.') >= required_version.split('.')