def UpdateSubmodules(self, remote=False): with log.info('Updating submodules in %s...', self.path): with Chdir(self.path, quiet=self.quiet): if os.path.isfile('.gitmodules'): more_flags = [] if remote: more_flags.append('--remote') cmd([ 'git', 'submodule', 'update', '--init', '--recursive' ] + more_flags, echo=not self.quiet, critical=True)
def GetRepoState(self, remote=None, quiet=None): if quiet is None: quiet = self.quiet self.current_branch = None self.current_commit = None if not os.path.isdir(self.path): log.warn('Could not find %s.', self.path) return with Chdir(self.path, quiet=self.quiet): if self.UpdateRemotes(remote, quiet=quiet): self.current_branch = Git.GetBranch(quiet=not quiet) self.current_commit = Git.GetCommit(short=False, quiet=not quiet)
def Pull(self, remote='origin', branch='HEAD', commit=None, tag=None, cleanup=False): if branch == 'HEAD': branch = self.remotes[remote].head_branch if self.submodule: log.error('Submodules should not call Pull!') return if not os.path.isdir(self.path): cmd(['git', 'clone', self.remotes[remote].fetch_uri, self.path], echo=not self.quiet or self.noisy_clone, critical=True, show_output=not self.quiet or self.noisy_clone, env=self.noPasswordEnv) with Chdir(self.path, quiet=self.quiet): if cleanup: cmd(['git', 'clean', '-fdx'], echo=not self.quiet, critical=True) cmd(['git', 'reset', '--hard'], echo=not self.quiet, critical=True) if self.current_branch != branch: ref = 'remotes/{}/{}'.format(remote, branch) cmd(['git', 'checkout', '-B', branch, ref, '--'], echo=not self.quiet, critical=True) if tag is not None: commit = self._resolveTagNoChdir(tag) if commit is not None: cmd(['git', 'checkout', commit], echo=not self.quiet, critical=True) else: if self.current_commit != self.remote_commit: cmd([ 'git', 'reset', '--hard', '{}/{}'.format( remote, branch) ], echo=not self.quiet, critical=True) if self.UsesLFS(): log.info('git-lfs detected!') cmd(['git', 'lfs', 'pull'], echo=not self.quiet, critical=True) return True
def GetRemoteState(self, remote='origin', branch='master'): with Chdir(self.path, quiet=self.quiet): ret = cmd_output(['git', 'fetch', '-q'], echo=not self.quiet) if not ret: return False stdout, stderr = ret for line in (stdout + stderr).split('\n'): line = line.strip() if line == '': continue if line.startswith('fatal:'): log.error('[git] ' + line) return False remoteinfo = Git.LSRemote(remote, branch) if remoteinfo is None: return False ref = 'refs/heads/' + branch if ref in remoteinfo: self.remote_commit = remoteinfo[ref] return True
def Pull(self, remote='origin', branch='master', cleanup=False): if not os.path.isdir(self.path): cmd(['git', 'clone', self.remotes[remote], self.path], echo=not self.quiet or self.noisy_clone, critical=True, show_output=not self.quiet or self.noisy_clone) with Chdir(self.path, quiet=self.quiet): if cleanup: cmd(['git', 'clean', '-fdx'], echo=not self.quiet, critical=True) cmd(['git', 'reset', '--hard'], echo=not self.quiet, critical=True) if self.current_branch != branch: ref = 'remotes/{}/{}'.format(remote, branch) cmd(['git', 'checkout', '-B', branch, ref, '--'], echo=not self.quiet, critical=True) if self.current_commit != self.remote_commit: cmd(['git', 'reset', '--hard', '{}/{}'.format(remote, branch)], echo=not self.quiet, critical=True) return True
def GetRemoteState(self, remote='origin', branch='HEAD', quiet=None): if quiet is None: quiet = self.quiet with Chdir(self.path, quiet=self.quiet): ret = cmd_output( ['git', 'fetch', '-q', '--all', '--prune', '--tags'], echo=not quiet, env=self.noPasswordEnv) if not ret: return False stdout, stderr = ret for line in (stdout + stderr).decode('utf-8').split('\n'): # if not quiet: # print(line) line = line.strip() if line == '': continue if line.startswith('fatal:'): log.error('[git] ' + line) return False for _remote in self.remotes.values(): _remote.fetched = False self.UpdateRemotes(remote=remote, quiet=quiet) if branch == 'HEAD': branch = self.remotes[remote].findBranch(branch) remoteinfo = Git.LSRemote(remote, branch, quiet=quiet) if remoteinfo is None: return False if branch == 'HEAD': ref = 'HEAD' elif '/' not in branch: ref = 'refs/heads/' + branch if ref in remoteinfo: self.remote_commit = remoteinfo[ref] return True
def GetRepoState(self): with Chdir(self.path, quiet=self.quiet): if self.UpdateRemotes(): self.current_branch = Git.GetBranch() self.current_commit = Git.GetCommit(short=False)
def ResolveTag(self, tag): with Chdir(self.path, quiet=self.quiet): return self._resolveTagNoChdir(tag)