本文整理汇总了Python中git.Git.current_branch方法的典型用法代码示例。如果您正苦于以下问题:Python Git.current_branch方法的具体用法?Python Git.current_branch怎么用?Python Git.current_branch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.current_branch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import current_branch [as 别名]
class Worker:
"""The worker Class."""
def __init__(self, args):
"""Constructor."""
self.args = args
self.git = Git(args)
def branches_to_be_deleted(self):
"""Return branches to be deleted."""
branches = self.branches_to_be_deleted_excluding_skipped()
if len(branches) > 0:
Formatter.print_pretty_warn_message("Following local branches would \
be deleted:")
return branches
else:
Formatter.print_pretty_fail_message("No branches to be deleted")
return []
def branches_to_be_deleted_excluding_skipped(self):
"""Return branches to be deleted except pattern matching branches."""
branches = list(
set(
self.git.merged_branches()
).difference(
self.git.pattern_matching_branches())
)
self.exclude_current_branch(branches)
return branches
def delete_branches(self, remote=False):
"""Delete the branches."""
"""If Remote=True, deletes remote branches as well."""
if len(self.branches_to_be_deleted()) > 0:
self.delete_local_branches()
if remote:
self.delete_remote_branches()
Formatter.print_pretty_ok_message("Cleaned Successfully!!")
def delete_remote_branches(self):
"""Delete remote branches."""
try:
os.popen("git push origin --delete " + " ".join(
self.branches_to_be_deleted())
)
except:
print "There was an error deleting remote branches: ",
sys.exc_info()[0]
def delete_local_branches(self):
"""Delete local branches."""
os.popen("git branch -D " + " ".join(self.branches_to_be_deleted()))
def exclude_current_branch(self, branches):
"""Exclude current branch from list of branches to be deleted."""
if(self.git.current_branch() in branches):
branches.remove(self.git.current_branch())
示例2: Project
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import current_branch [as 别名]
class Project():
def __init__(self):
self.tree = ElementTree();
self.git = Git()
if not os.path.exists(PROJECT_CONFIG_PATH):
os.mkdir(PROJECT_CONFIG_PATH)
try:
self.tree.parse(PROJECT_CONFIG_FILE)
except:
root = Element('Project', {'name':os.path.basename(os.getcwd())})
self.tree._setroot(root)
def save(self):
self.tree.write(PROJECT_CONFIG_FILE, xml_declaration=True, method="xml")
def iter(self):
return self.tree.iter('SubProject')
def find(self, name):
for i in self.iter():
if i.get('name') == name:
return i
def inSubProject(self):
cwd = os.getcwd()
for node in self.iter():
name = node.get('name')
print("")
print("On:%s" % name)
print("***************************************")
os.chdir("/".join([cwd, name]))
yield
print("***************************************")
def clone(self):
for module in self.iter():
self.git.clone(module)
def __init_module(self, module):
if not os.path.exists(module):
print("module %s not exists." % module)
return None
cwd = os.getcwd()
os.chdir("/".join([cwd, module]))
if self.git.is_repo():
node = Element('SubProject')
node.set("name", module)
current_branch = self.git.current_branch()
if current_branch != None:
node.set("branch", current_branch)
remote_uri = self.git.current_remote_uri(branch=current_branch)
if remote_uri != None:
node.set("uri", remote_uri)
else:
node = None
else:
print("fatal: Not a git repository")
node = None
os.chdir(cwd)
return node
def __append_ignore_file(self, module):
if os.path.exists(".gitignore"):
ignoreFile = open(".gitignore","r")
for line in ignoreFile:
if module == line.strip():
return
ignoreFile.close()
ignoreFile = open(".gitignore", "a")
ignoreFile.write(module + "\n")
ignoreFile.close()
def __remove_ignore_file(self, modules):
if os.path.exists(".gitignore"):
ignoreFile = open(".gitignore","r")
print modules
data = [line.strip() for line in ignoreFile if not (line.strip() in modules)]
ignoreFile = open(".gitignore", "w")
ignoreFile.write("\n".join(data)+"\n")
ignoreFile.close()
data = None
def append(self, module):
if module == None:
return -1
node = self.find(module)
root = self.tree.getroot()
if node != None:
root.remove(node)
node = self.__init_module(module)
if node == None:
return -1
else:
root.append(node)
self.__append_ignore_file(module)
self.save()
return 0
#.........这里部分代码省略.........