def do(self): path = self.path if not path or not core.isfile(path): raise UsageError(N_('Error: Cannot find commit template'), N_('%s: No such file or directory.') % path) self.model.set_directory(os.path.dirname(path)) self.model.set_commitmsg(core.read(path))
def is_git_dir(d): """From git's setup.c:is_git_directory().""" if core.isdir(d) and core.isdir(join(d, "objects")) and core.isdir(join(d, "refs")): headref = join(d, "HEAD") return core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith("refs")) return is_git_file(d)
def is_git_dir(git_dir): """From git's setup.c:is_git_directory().""" result = False if git_dir: headref = join(git_dir, 'HEAD') if (core.isdir(git_dir) and (core.isdir(join(git_dir, 'objects')) and core.isdir(join(git_dir, 'refs'))) or (core.isfile(join(git_dir, 'gitdir')) and core.isfile(join(git_dir, 'commondir')))): result = (core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith('refs/'))) else: result = is_git_file(git_dir) return result
def is_git_dir(d): """From git's setup.c:is_git_directory().""" if (core.isdir(d) and core.isdir(join(d, 'objects')) and core.isdir(join(d, 'refs'))): headref = join(d, 'HEAD') return (core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith('refs'))) return is_git_file(d)
def get_patches_from_paths(paths): paths = [core.decode(p) for p in paths] patches = [p for p in paths if core.isfile(p) and ( p.endswith('.patch') or p.endswith('.mbox'))] dirs = [p for p in paths if core.isdir(p)] dirs.sort() for d in dirs: patches.extend(get_patches_from_dir(d)) return patches
def get_patches_from_paths(paths): paths = [core.decode(p) for p in paths] patches = [ p for p in paths if core.isfile(p) and (p.endswith('.patch') or p.endswith('.mbox')) ] dirs = [p for p in paths if core.isdir(p)] dirs.sort() for d in dirs: patches.extend(get_patches_from_dir(d)) return patches
def _read_git_head(head, default='master', git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if core.islink(head): refs_heads = core.realpath(git.git_path('refs', 'heads')) path = core.abspath(head).replace('\\', '/') if path.startswith(refs_heads + '/'): return path[len(refs_heads) + 1:] # Common .git/HEAD "ref: refs/heads/master" file elif core.isfile(head): data = core.read(head).rstrip() ref_prefix = 'ref: ' if data.startswith(ref_prefix): return data[len(ref_prefix):] # Detached head return data return default
def _read_git_head(head, default="master", git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if core.islink(head): refs_heads = core.realpath(git.git_path("refs", "heads")) path = core.abspath(head).replace("\\", "/") if path.startswith(refs_heads + "/"): return path[len(refs_heads) + 1 :] # Common .git/HEAD "ref: refs/heads/master" file elif core.isfile(head): data = core.read(head).rstrip() ref_prefix = "ref: " if data.startswith(ref_prefix): return data[len(ref_prefix) :] # Detached head return data return default
def _read_git_head(head, default='master', git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if core.islink(head): refs_heads = core.realpath(git.git_path('refs', 'heads')) path = core.abspath(head).replace('\\', '/') if path.startswith(refs_heads + '/'): return path[len(refs_heads)+1:] # Common .git/HEAD "ref: refs/heads/master" file elif core.isfile(head): data = core.read(head).rstrip() ref_prefix = 'ref: ' if data.startswith(ref_prefix): return data[len(ref_prefix):] # Detached head return data return default
def is_git_file(f): return core.isfile(f) and '.git' == os.path.basename(f)