当前位置: 首页>>代码示例>>Python>>正文


Python Git.status方法代码示例

本文整理汇总了Python中git.Git.status方法的典型用法代码示例。如果您正苦于以下问题:Python Git.status方法的具体用法?Python Git.status怎么用?Python Git.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Git的用法示例。


在下文中一共展示了Git.status方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_message

# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import status [as 别名]
async def on_message(message):
	if client.sleeping:
		if message.content == '!wake':
			client.sleeping = False
			await client.send_message(message.channel, 'SolBot online!')
	else:
		if message.content == '!sleep':
			client.sleeping = True
			await client.send_message(message.channel, 'Going to sleep...')
		elif message.content == '!update':
			g = Git(os.path.dirname(os.path.abspath(__file__)))
			tmp = await client.send_message(message.channel, 'Pulling new code...')
			g.pull()
			await client.edit_message(tmp, 'Code pulled. Restarting...')
			client.logout()
			os.execv(sys.executable, ['python3.5'] + sys.argv)
		elif message.content == '!gitstatus':
			g = Git(os.path.dirname(os.path.abspath(__file__)))
			tmp = await client.send_message(message.channel, 'Checking status...')
			g.fetch()
			p = re.compile('Your branch is.*by (\d+) commits.*')
			m = p.match(g.status())
			if m:
				await client.edit_message(tmp, 'I am behind by {} commits'.format(m.group(1)))
			else:
				await client.edit_message(tmp, 'I am up to date!')
开发者ID:flip40,项目名称:SolBot,代码行数:28,代码来源:solbot.py

示例2: GitWrapper

# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import status [as 别名]
class GitWrapper(object):
    """
    A wrapper for repo.git providing better stdout handling + better exeptions.

    It is preferred to repo.git because it doesn't print to stdout
    in real time. In addition, this wrapper provides better error
    handling (it provides stdout messages inside the exception, too).
    """

    def __init__(self, repo):
        if repo:
            #: :type: git.Repo
            self.repo = repo
            #: :type: git.Git
            self.git = self.repo.git
        else:
            #: :type: git.Git
            self.git = Git()

    def __del__(self):
        # Is the following true?

        # GitPython runs persistent git processes in  the working directory.
        # Therefore, when we use 'git up' in something like a test environment,
        # this might cause troubles because of the open file handlers (like
        # trying to remove the directory right after the test has finished).
        # 'clear_cache' kills the processes...

        if platform.system() == 'Windows':  # pragma: no cover
            pass
            # ... or rather "should kill", because but somehow it recently
            # started to not kill cat_file_header out of the blue (I even
            # tried running old code, but the once working code failed).
            # Thus, we kill it  manually here.
            if self.git.cat_file_header is not None:
                subprocess.call(("TASKKILL /F /T /PID {0} 2>nul 1>nul".format(
                    str(self.git.cat_file_header.proc.pid)
                )), shell=True)
            if self.git.cat_file_all is not None:
                subprocess.call(("TASKKILL /F /T /PID {0} 2>nul 1>nul".format(
                    str(self.git.cat_file_all.proc.pid)
                )), shell=True)

        self.git.clear_cache()

    def run(self, name, *args, **kwargs):
        """ Run a git command specified by name and args/kwargs. """

        tostdout = kwargs.pop('tostdout', False)
        stdout = six.b('')

        # Execute command
        cmd = getattr(self.git, name)(as_process=True, *args, **kwargs)

        # Capture output
        while True:
            output = cmd.stdout.read(1)

            # Print to stdout
            if tostdout:
                sys.stdout.write(output.decode('utf-8'))
                sys.stdout.flush()

            stdout += output

            if output == six.b(""):
                break

        # Wait for the process to quit
        try:
            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'
#.........这里部分代码省略.........
开发者ID:Javex,项目名称:PyGitUp,代码行数:103,代码来源:git_wrapper.py

示例3: GitModel

# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import status [as 别名]
class GitModel(QObject) :

    statusRefreshed = Signal(str)

    def __init__(self):
        super(GitModel, self).__init__(None)
        self.configs = dict();
        self.repo = None
        
    def connect(self, path):
        self.repo = Repo(path)
        assert self.repo.bare == False
        
        self.git = Git(path)
        self.git.init()
        
    def run(self, cmd):
        print "run " + str(cmd)
        process = Popen(cmd)
        process.wait()
        print "returncode is " + str(process.returncode)
        return process.returncode
       
    def refreshStatus(self):
        self.status = self.git.status()    
        self.indexModel = self.getIndexModel()
        
        self.statusRefreshed.emit(self.status)
        
    def stageFile(self, path):
        return self.run(['git', 'add', path])
        
    def unstageFile(self, path):
        return self.run(['git', 'reset', 'HEAD', path])

    def executeCommit(self, msg):
        if msg is None or len(msg) == 0:
            print 'Message is empty'
            return -1

        rslt = self.run(['git', 'commit', '-m', msg])

        return rslt
    
    def undoRecentCommit(self):
        rslt = self.run(['git', 'reset', '--soft', 'HEAD^'])        
        return rslt

    def getIndexStatus(self):
        fileIndex = dict()
        
        MODIFIED = '#\tmodified:   '
        RENAMED = '#\trenamed:    '
        NEW_FILE = '#\tnew file:   '
        COMMITTED = '# Changes to be committed:'
        #CHANGED = '# Changed but not updated:'
        CHANGED = '# Changes not staged for commit:'
        UNTRACKED = '# Untracked files:'
        UNTRACKED_INTENT = '#    '
        

        self.isIdxClear = True
        lines = self.status.splitlines()
        type = ''
        for l in lines:
            print l
            
            #index
            if l == COMMITTED :
                type = 'I'
                self.isIdxClear = False
                
            #working directory
            elif l == CHANGED :
                type = 'W'

            if l.startswith(MODIFIED) :
                path = l[len(MODIFIED):]
                
                if type == 'I':
                    fileIndex[path] = 'M'
                elif type == 'W':
                    if path in fileIndex.keys():
                        fileIndex[path] += 'C'
                    else:
                        fileIndex[path] = 'C'
                continue
            
            if l.startswith(RENAMED) :
                path = l[len(RENAMED):].split(' ')[2]               
                fileIndex[path] = 'R'
            
            if l.startswith(NEW_FILE) :
                path = l[len(NEW_FILE):]                
                fileIndex[path] = 'N'                
                
            if l == UNTRACKED :
                type = 'U'
            
                idx = lines.index(l) + 3
#.........这里部分代码省略.........
开发者ID:flexdimension,项目名称:GitGrown_old,代码行数:103,代码来源:GitModel.py


注:本文中的git.Git.status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。