def pluck_dotgit(path_list): """ pluck_dotgit on success, returns a list that is a copy of the given list, with the trailing ".git" removed off the items returns None on failures """ if path_list is None: return None ret_list = [] for it in path_list: local_it = it if it.endswith(os.sep): # plucks out the trailing "/" on unices local_it = it[:len(it)-1] if local_it.endswith(".git"): local_it = path_utils.backpedal_path(local_it) ret_list.append(local_it) return ret_list
#!/usr/bin/env python import os import sys import path_utils from subprocess import call def is_repo_root(path): if path is None: return False if not os.path.exists(path): return False if path.endswith(".git") or path.endswith(".git" + os.sep): return True if __name__ == "__main__": curpath = os.getcwd() # uses current working dir by default if len(sys.argv) > 1: # override with cmdline arg curpath = sys.argv[1] while not is_repo_root(os.path.join(curpath, ".git")): curpath = path_utils.backpedal_path(curpath) if curpath is None: sys.exit(1) call("inline_echo.py '%s'" % curpath, shell=True)