本文整理汇总了Python中git.Git.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Git.commit方法的具体用法?Python Git.commit怎么用?Python Git.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.commit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_commit_with_no_message
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import commit [as 别名]
def test_commit_with_no_message(self):
mock_repo = MagicMock()
mock_index = MagicMock()
mock_remotes = MagicMock()
mock_repo.index = mock_index
mock_repo.remotes.origin = mock_remotes
with patch.multiple('git', Repo=mock_repo):
git = Git('~/path/to/repo')
objects = ['simple_object', 'more_complex_one']
git.commit(objects, '')
示例2: addSuperModuleCommit
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import commit [as 别名]
def addSuperModuleCommit(self, id, hash, url, who, branch, project):
self.log.debug("branch: " + branch + ", project:" + project)
hasSuperModule = False
isSuperModuleBr = False
self.log.debug("Project names: " + str(self.config.projects))
projectNames = self.config.projects.keys()
for proj in projectNames:
self.log.debug("project: " + project + " proj: " + proj)
if project.lower() == proj:
hasSuperModule = True
break
for br in self.config.branches:
if branch == br:
isSuperModuleBr = True
break
self.log.debug("isSuperModuleBr: " + str(isSuperModuleBr) + " hasSuperModule: " + str(hasSuperModule))
if isSuperModuleBr and hasSuperModule:
self.log.debug("Git Profile Path: " + str(self.config.profile))
git = Git(self.config.profile)
self.checkoutTrackingBranch(git, branch)
git.pull()
git.submodule("update","--init")
gitSubmoduleProfile = {'git':self.config.superRepoPath + self.config.projects[project.lower()]}
gitSubmodule = Git(gitSubmoduleProfile)
self.log.debug("checking out hash: " + hash)
gitSubmodule.fetch()
if self.isOptOut(gitSubmodule, hash):
return
gitSubmodule.checkout(hash, True)
git.add(".")
commitMsg = "Auto checkin: " + self.getCommitMessage(gitSubmodule, hash) + "\nuser:" + who + "\nhash:" + hash + "\nproject: " + project
self.log.debug("commiting in super module: " + commitMsg)
git.commit(commitMsg)
self.log.debug("pushing super module to branch: " + branch)
git.push(branch)
else:
self.log.debug("No super module commit is required.")
示例3: created_quark
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import commit [as 别名]
def created_quark(self, sender, new_quark):
options = sender.options
if self.git_is_installed():
g = Git(options['path'])
g.init()
default_ignore = os.path.join(os.path.dirname(__file__), '..', 'default_gitignore.txt')
ignore_path = os.path.join(options['path'], '.gitignore')
with open(ignore_path, 'w') as ignore_file, open(default_ignore, 'r') as default_file:
ignore_file.write(default_file.read())
user_ignores = settings.user_gitignore()
if user_ignores:
ignore_file.write('\n#SUPPLIED FROM ~/.qpmignore\n\n')
ignore_file.write(user_ignores)
g.add(new_quark.get_quarkfile_path(options['path']))
g.commit(m='Created quarkfile.')
g.add('.gitignore')
g.commit(m='Created gitignore.')
g.add('.')
if Repo(options['path']).is_dirty():
g.commit(m='Initial commit of existing files.')
g.tag(options['version'])
else:
self.msg(
'WARNING: Git is not installed. Try http://git-scm.com/ or run the following:\n'
+ '\truby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"; brew install git'
)
示例4: test_commit_succesfully_with_multiple_objects
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import commit [as 别名]
def test_commit_succesfully_with_multiple_objects(self):
mock_repo = MagicMock()
mock_index = MagicMock()
mock_remotes = MagicMock()
mock_repo.index = mock_index
mock_repo.remotes.origin = mock_remotes
with patch.multiple('git', Repo=MagicMock(return_value=mock_repo)):
git = Git('~/path/to/repo')
objects = ['simple_object', 'more_complex_one']
commit_message = 'simple commit message'
git.commit(objects, commit_message)
git.commit(objects, commit_message, action='remove')
mock_index.add.assert_called_once_with(objects)
mock_index.remove.assert_called_once_with(objects)
mock_index.commit.has_calls([call(commit_message), call(commit_message)])
eq_(mock_remotes.fetch.call_count, 2)
eq_(mock_remotes.pull.call_count, 2)
eq_(mock_remotes.push.call_count, 2)
示例5: Git
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import commit [as 别名]
if not os.path.isdir(dirpath):
os.mkdir(dirpath)
g = Git(dirpath)
# If is not Git repository, git init
if not git.repo.fun.is_git_dir(dirpath):
# bare repository
if args.__dict__.get('b'):
repo = g.init(dirpath, bare=True)
else:
# local repository
g.init()
# Make .gitignore
if not os.path.isfile(dirpath + '/.gitignore'):
f = open(dirpath + '/.gitignore', 'w')
f.write('')
f.close()
# git add .gitignore and first commit
if g.untracked_files or g.is_dirty():
# git add
g.add('.gitignore')
# git commit
g.commit(m='First commit')
except RuntimeError as e:
sys.stderr.write("ERROR: %s\n" % e)
示例6: initialize
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import commit [as 别名]
def initialize(path, branch):
try:
repo = Repo(path)
git = Git(path)
except InvalidGitRepositoryError as err:
print "Not a valid Git repo: %s" % err
sys.exit("Run `git init %s` first" % err)
output = ['Initializing in %s [%s]' % (path, branch)]
current_branch = repo.active_branch
if branch in [b.name for b in repo.branches]:
output.append("error: A branch named '%s' already exists in this repo!"
% branch)
return output
output.append("--> Stashing current branch contents [%s]" % current_branch)
try:
cmd = git.stash(u=True)
for line in cmd.splitlines():
output.append(" %s" % line)
except GitCommandError as err:
output.append("error: %s" % err)
return output
output.append("--> Switching to branch '%s'" % branch)
try:
git.checkout(B=branch)
except GitCommandError as err:
output.append("error: %s" % err)
return output
output.append("--> Clearing current files and committing")
try:
files = os.listdir(path)
files.remove('.git')
for entry in files:
git.rm(entry, r=True, f=True)
cmd = git.commit(m="Clearing files in preparation for git-pm")
for line in cmd.splitlines():
output.append(" %s" % line)
except GitCommandError as err:
output.append("error: %s" % err)
return output
output.append("--> Creating git-pm file structure and committing")
try:
for directory in DIRECTORIES:
dir_path = os.path.join(path, directory)
gitkeep = os.path.join(dir_path, '.gitkeep')
os.mkdir(dir_path)
with open(gitkeep, 'a'):
os.utime(gitkeep, None)
cmd = git.commit(m="Created git-pm file structure")
for line in cmd.splitlines():
output.append(" %s" % line)
except GitCommandError as err:
output.append("error: %s" % err)
return output
output.append("--> Returning to previous branch and popping stash")
try:
git.checkout(current_branch)
git.stash("pop")
except GitCommandError as err:
output.append("error: %s" % err)
return output
return output