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(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 process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(0) if args.git_path: # Adds git to the PATH. This is needed on Windows. path_entries = core.getenv('PATH', '').split(os.pathsep) path_entries.insert(0, os.path.dirname(core.decode(args.git_path))) compat.setenv('PATH', os.pathsep.join(path_entries)) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): sys.stderr.write("fatal: '%s' is not a directory. " 'Consider supplying -r <path>.\n' % repo) sys.exit(-1) # We do everything relative to the repo root os.chdir(args.repo) return repo
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(0) # Handle session management restore_session(args) if args.git_path: # Adds git to the PATH. This is needed on Windows. path_entries = core.getenv('PATH', '').split(os.pathsep) path_entries.insert(0, os.path.dirname(core.decode(args.git_path))) compat.setenv('PATH', os.pathsep.join(path_entries)) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' 'Please specify --repo <path>.') % repo core.stderr(errmsg) sys.exit(-1) # We do everything relative to the repo root os.chdir(args.repo) return repo
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(0) # Handle session management restore_session(args) if args.git_path: # Adds git to the PATH. This is needed on Windows. path_entries = core.getenv('PATH', '').split(os.pathsep) path_entries.insert(0, os.path.dirname(core.decode(args.git_path))) compat.setenv('PATH', os.pathsep.join(path_entries)) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' 'Please specify a correct --repo <path>.') % repo core.stderr(errmsg) sys.exit(-1) # We do everything relative to the repo root os.chdir(args.repo) return repo
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'))): result = (core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith('refs/'))) else: result = is_git_file(git_dir) return result
def write_json(values, path): try: parent = os.path.dirname(path) if not core.isdir(parent): core.makedirs(parent) with core.xopen(path, 'wt') as fp: json.dump(values, fp, indent=4) except: sys.stderr.write('git-cola: error writing "%s"\n' % path)
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 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 save(self): path = self.path() try: parent = os.path.dirname(path) if not core.isdir(parent): core.makedirs(parent) with core.xopen(path, 'wb') as fp: json.dump(self.values, fp, indent=4) except: sys.stderr.write('git-cola: error writing "%s"\n' % path)
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 process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(EX_OK) # Handle session management restore_session(args) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith('file:'): repo = repo[len('file:'):] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' 'Please specify a correct --repo <path>.') % repo core.stderr(errmsg) sys.exit(EX_USAGE)
def process_args(args): if args.version: # Accept 'git cola --version' or 'git cola version' version.print_version() sys.exit(EX_OK) # Handle session management restore_session(args) # Bail out if --repo is not a directory repo = core.decode(args.repo) if repo.startswith("file:"): repo = repo[len("file:") :] repo = core.realpath(repo) if not core.isdir(repo): errmsg = N_('fatal: "%s" is not a directory. ' "Please specify a correct --repo <path>.") % repo core.stderr(errmsg) sys.exit(EX_USAGE) # We do everything relative to the repo root os.chdir(args.repo) return repo
def worktree(self): if self._worktree: return self._worktree self.git_dir() if self._git_dir: curdir = self._git_dir else: curdir = core.getcwd() if is_git_dir(join(curdir, ".git")): return curdir # Handle bare repositories if len(os.path.basename(curdir)) > 4 and curdir.endswith(".git"): return curdir if "GIT_WORK_TREE" in os.environ: self._worktree = core.getenv("GIT_WORK_TREE") if not self._worktree or not core.isdir(self._worktree): if self._git_dir: gitparent = join(core.abspath(self._git_dir), "..") self._worktree = core.abspath(gitparent) self.set_cwd(self._worktree) return self._worktree
def worktree(self): if self._worktree: return self._worktree self.git_dir() if self._git_dir: curdir = self._git_dir else: curdir = core.getcwd() if is_git_dir(join(curdir, '.git')): return curdir # Handle bare repositories if (len(os.path.basename(curdir)) > 4 and curdir.endswith('.git')): return curdir if 'GIT_WORK_TREE' in os.environ: self._worktree = core.getenv('GIT_WORK_TREE') if not self._worktree or not core.isdir(self._worktree): if self._git_dir: gitparent = join(core.abspath(self._git_dir), '..') self._worktree = core.abspath(gitparent) self.set_cwd(self._worktree) return self._worktree