def get_files(self): '''Return a list of changed files.''' trace = False and not g.unitTesting def readable(fn): for suffix in ( 'commit_timestamp.json', '.db', '.leo', '.zip', ): if fn.strip().endswith(suffix): return False return True command = 'git diff --name-only %s %s' % (self.rev1 or '', self.rev2 or '') files = [ z.strip() for z in g.execGitCommand(command, self.repo_dir) if readable(z) ] if trace: g.trace(command) g.printList(files) return files
def get_file_from_branch(self, branch, fn): '''Get the file from the hed of the given branch.''' # Get the file using git. command = 'git show %s:%s' % (branch, fn) directory = self.repo_dir lines = g.execGitCommand(command, directory) s = ''.join(lines) return g.toUnicode(s).replace('\r', '')
def get_file_from_branch(self, branch, fn): """Get the file from the hed of the given branch.""" # Get the file using git. command = f"git show {branch}:{fn}" directory = self.repo_dir lines = g.execGitCommand(command, directory) s = ''.join(lines) return g.toUnicode(s).replace('\r', '')
def get_file_from_branch(self, branch, fn): '''Get the file from the hed of the given branch.''' # Get the file using git. command = 'git show %s:%s' % (branch, fn) directory = self.repo_dir lines = g.execGitCommand(command, directory) s = ''.join(lines) return g.toUnicode(s).replace('\r','')
def get_files(self, rev1, rev2): """Return a list of changed files.""" command = f"git diff --name-only {(rev1 or '')} {(rev2 or '')}" files = [ z.strip() for z in g.execGitCommand(command, self.repo_dir) if not z.strip().endswith(('.db', '.zip')) # #1781: Allow diffs of .leo files. ] return files
def get_revno(self, revspec, abbreviated=True): """Return the abbreviated hash the given revision spec.""" if revspec: # Return only the abbreviated hash for the revspec. command = 'git show --format=%%%s --no-patch %s' % ( 'h' if abbreviated else 'H', revspec) lines = g.execGitCommand(command, self.repo_dir) return ''.join(lines).strip() return 'uncommitted'
def get_file_from_branch(self, branch, fn): """Get the file from the head of the given branch.""" # #2143 directory = self.get_directory() if not directory: return '' command = f"git show {branch}:{fn}" lines = g.execGitCommand(command, directory) s = ''.join(lines) return g.toUnicode(s).replace('\r', '')
def get_revno(self, revspec, abbreviated=True): """Return the abbreviated hash the given revision spec.""" if not revspec: return 'uncommitted' # Return only the abbreviated hash for the revspec. format_s = 'h' if abbreviated else 'H' command = f"git show --format=%{format_s} --no-patch {revspec}" directory = self.get_directory() lines = g.execGitCommand(command, directory=directory) return ''.join(lines).strip()
def get_revno(self, revspec, abbreviated=True): '''Return the abbreviated hash the given revision spec.''' if revspec: # Return only the abbreviated hash for the revspec. command = 'git show --format=%%%s --no-patch %s' % ( 'h' if abbreviated else 'H', revspec) lines = g.execGitCommand(command, self.repo_dir) return ''.join(lines).strip() else: return 'uncommitted'
def get_files(self, rev1, rev2): """Return a list of changed files.""" # #2143 directory = self.get_directory() if not directory: return [] command = f"git diff --name-only {(rev1 or '')} {(rev2 or '')}" # #1781: Allow diffs of .leo files. return [ z.strip() for z in g.execGitCommand(command, directory) if not z.strip().endswith(('.db', '.zip')) ]
def get_files(self): '''Return a list of changed files.''' if self.rev1 and self.rev2: command = 'git diff --name-only %s %s' % (self.rev1, self.rev2) else: command = 'git diff --name-only' files = [ z.strip() for z in g.execGitCommand(command, self.repo_dir) if z.strip().endswith('.py') ] # g.printList(files) return files
def get_files(self, rev1, rev2): '''Return a list of changed files.''' def readable(fn): for suffix in ('commit_timestamp.json', '.db', '.leo', '.zip', ): if fn.strip().endswith(suffix): return False return True command = 'git diff --name-only %s %s' % (rev1 or '', rev2 or '') files = [ z.strip() for z in g.execGitCommand(command, self.repo_dir) if readable(z) ] return files
def get_file_from_rev(self, rev, fn): '''Get the file from the given rev, or the working directory if None.''' if rev: # Get the file using git. command = 'git show %s:%s' % (rev, fn) lines = g.execGitCommand(command, self.repo_dir) s = ''.join(lines) else: # Get the file from the working directory. path = g.os_path_finalize_join(self.repo_dir, fn) if g.os_path_exists(path): with open(path, 'r') as f: s = f.read() else: g.trace('not found:', path) s = '' return g.toUnicode(s).replace('\r','')
def get_lines_from_rev(self, rev, fn): '''Get the file from the given rev, or the working directory if None.''' if rev: command = 'git show %s:%s' % (rev, fn) lines = g.execGitCommand(command, self.repo_dir) else: # Get the file from the working directory. path = g.os_path_finalize_join(self.repo_dir, fn) if g.os_path_exists(path): with open(path, 'r') as f: s = f.read().replace('\r','') s = g.toUnicode(s) lines = g.splitLines(s) else: g.trace('not found:', path) lines = [] return lines
def diff_pull_request(self): """ Create a Leonine version of the diffs that would be produced by a pull request between two branches. """ directory = self.get_directory() if not directory: return aList = g.execGitCommand("git rev-parse devel", directory) if aList: devel_rev = aList[0] devel_rev = devel_rev[:8] self.diff_two_revs( rev1=devel_rev, # Before: Latest devel commit. rev2='HEAD', # After: Lastest branch commit ) else: g.es_print('FAIL: git rev-parse devel')
def diff_pull_request(self, base_branch_name='devel', directory=None): """ Create a Leonine version of the diffs that would be produced by a pull request between two branches. """ if not directory: directory = os.path.join(g.app.loadDir, '..', '..') aList = g.execGitCommand("git rev-parse devel", directory) if aList: devel_rev = aList[0] devel_rev = devel_rev[:8] self.diff_two_revs( rev1=devel_rev, # Before: Latest devel commit. rev2='HEAD', # After: Lastest branch commit directory=directory, ) else: g.es_print('FAIL: git rev-parse devel')
def get_file_from_rev(self, rev, fn): """Get the file from the given rev, or the working directory if None.""" path = g.os_path_finalize_join(self.repo_dir, fn) if not g.os_path_exists(path): return '' if rev: # Get the file using git. # Use the file name, not the path. command = f"git show {rev}:{fn}" lines = g.execGitCommand(command, self.repo_dir) return g.toUnicode(''.join(lines)).replace('\r', '') try: with open(path, 'rb') as f: # Was 'r' b = f.read() return g.toUnicode(b).replace('\r', '') except Exception: g.es_print('Can not read', path) g.es_exception() return ''
def get_files(self): '''Return a list of changed files.''' trace = False and not g.unitTesting def readable(fn): for suffix in ('commit_timestamp.json', '.db', '.leo', '.zip', ): if fn.strip().endswith(suffix): return False return True command = 'git diff --name-only %s %s' % (self.rev1 or '', self.rev2 or '') files = [ z.strip() for z in g.execGitCommand(command, self.repo_dir) if readable(z) ] if trace: g.trace(command) g.printList(files) return files
def get_file_from_rev(self, rev, fn): """Get the file from the given rev, or the working directory if None.""" if rev: # Get the file using git. command = f"git show {rev}:{fn}" lines = g.execGitCommand(command, self.repo_dir) s = ''.join(lines) else: # Get the file from the working directory. path = g.os_path_finalize_join(self.repo_dir, fn) if g.os_path_exists(path): try: with open(path, 'rb') as f: # Was 'r' s = f.read() except Exception: g.es_print('Can not read', path) g.es_exception() s = '' else: g.trace('not found:', path) s = '' return g.toUnicode(s).replace('\r', '')
def get_file_from_rev(self, rev, fn): """Get the file from the given rev, or the working directory if None.""" # #2143 directory = self.get_directory() if not directory: return '' path = g.os_path_finalize_join(directory, fn) if not g.os_path_exists(path): g.trace(f"File not found: {path!r} fn: {fn!r}") return '' if rev: # Get the file using git. # Use the file name, not the path. command = f"git show {rev}:{fn}" lines = g.execGitCommand(command, directory) return g.toUnicode(''.join(lines)).replace('\r', '') try: with open(path, 'rb') as f: b = f.read() return g.toUnicode(b).replace('\r', '') except Exception: g.es_print('Can not read', path) g.es_exception() return ''