def test_find_git_root(): with fleeting_repo() as test_repo: test_repo.commit([('test_proj/test.txt', 'testing\n')]) git_root = test_repo.repo_root test_proj_root = os.path.join(git_root, 'test_proj') # should work both for subdirectories eq_(git_root, find_git_root(test_proj_root)) # and for top-level projects eq_(git_root, find_git_root(git_root))
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 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_find_git_root_barfs_on_non_repo(): with util.mk_tmpdir() as temp_dir: find_git_root(temp_dir)