def ls(project_root): """ Return a list of real, absolute paths to all the git-controlled files under the project root. """ git_root = git.find_git_root(project_root) # --full-tree = allow absolute path for final argument (pathname) # # --name-only = don't show the git id for the object, just the # file name # # -r = recurse into subdirs # # -z = null byte separate listings git_cmd_s = 'ls-tree --full-tree --name-only -r -z HEAD' # don't add the project root until after the split, in case it # contains spaces. git_cmd = git_cmd_s.split() git_cmd.append(project_root) with git.git_cmd(cmd=git_cmd, cwd=git_root) as out_f: fnames_z = out_f.read() return [ util.real_abs_path(fname=fname, parent=git_root) for fname in fnames_z.split('\0') # don't show '', which is just the root of the repo. if fname ]
def raw_log_stream(fname): """ Yield an open file-like containing the NULL byte delimited raw log entries for fname, which will be closed upon return. """ git_root = git.find_git_root(os.path.dirname(fname)) # -z = null byte separate log entries # # -w = ignore all whitespace when calculating changed lines # # --follow = follow file history through renames # # --patience = use the patience diff algorithm # # --encoding=utf-8 forces any logs that were not encoded as # utf-8 to be re-encoded as utf-8 before they are returned # # -p show patches (diffs) # # --reverse show the commits in chronological order # cmd = ("log -z -w --follow --patience --reverse -p " "--encoding=utf-8 -- ").split() # don't append the fname until after the split, as it might # contain spaces. cmd.append(fname) with git.git_cmd(cmd, cwd=git_root) as raw_log_entries_z: yield raw_log_entries_z
def ls(project_root): """ Return a list of real, absolute paths to all the git-controlled files under the project root. """ git_root = git.find_git_root(project_root) # --full-tree = allow absolute path for final argument (pathname) # # --name-only = don't show the git id for the object, just the # file name # # -r = recurse into subdirs # # -z = null byte separate listings git_cmd_s = 'ls-tree --full-tree --name-only -r -z HEAD' # don't add the project root until after the split, in case it # contains spaces. git_cmd = git_cmd_s.split() git_cmd.append(project_root) with git.git_cmd(cmd=git_cmd, cwd=git_root) as out_f: fnames_z = out_f.read() return [util.real_abs_path(fname=fname, parent=git_root) for fname in fnames_z.split('\0') # don't show '', which is just the root of the repo. if fname]
def test_git_cmd_returns_std_out(): with fleeting_repo() as test_repo: commit_msg = 'I remain committed.' test_repo.commit([('test.txt', 'testing\n')], commit_msg=commit_msg) with git_cmd(["log"], cwd=test_repo.repo_root) as output_f: ok_(commit_msg in util.utf8(output_f.read()))
def test_git_cmd_barfs_on_bad_cmd(): with git_cmd(["not_a_git_cmd"], cwd='.'): # should never get here ok_(False)
def test_can_call_git(): # just to make sure we've got a git exe and can test that bad args # are actually causing the exception in other tests of exceptions with git_cmd(["--version"], cwd='.') as out_f: ok_(out_f.read())