本文整理汇总了Python中git.Git.rm方法的典型用法代码示例。如果您正苦于以下问题:Python Git.rm方法的具体用法?Python Git.rm怎么用?Python Git.rm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.rm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import rm [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