def cmd_init(base_dir: "Path to dotkeeper base directory" = "~/.dotkeeper/"): """Initializes the dot keeper repo""" base_dir = os.path.expanduser(base_dir) repo_dir = os.path.join(base_dir, "repo") GIT_DIR = repo_dir if not os.path.exists(repo_dir): os.makedirs(repo_dir) git_helper(["init"], git_dir=GIT_DIR) config_file = os.path.join(base_dir, "config") if os.path.exists(config_file): print("Config file already exists!") else: # create new, empty config file. this will be the first commit into the repo cp = ConfigParser() cp.add_section("dotkeeper") cp.set("dotkeeper", "base_dir", base_dir) with open(config_file, "w") as f: cp.write(f) add_to_index(config_file, git_dir=GIT_DIR) root_tree = write_tree(git_dir=GIT_DIR) print("root_tree is %r" % root_tree) commit_hash = commit_tree(root_tree, "Initial commit", parent=None, git_dir=GIT_DIR) print("commit_hash is %r" % commit_hash) git_helper(["update-ref", "HEAD", commit_hash], git_dir=GIT_DIR) print("Done!")
def cmd_init(base_dir:"Path to dotkeeper base directory"="~/.dotkeeper/"): """Initializes the dot keeper repo""" base_dir = os.path.expanduser(base_dir) repo_dir = os.path.join(base_dir, "repo") GIT_DIR = repo_dir if not os.path.exists(repo_dir): os.makedirs(repo_dir) git_helper(["init"], git_dir=GIT_DIR) config_file = os.path.join(base_dir, "config") if os.path.exists(config_file): print("Config file already exists!") else: # create new, empty config file. this will be the first commit into the repo cp = ConfigParser() cp.add_section("dotkeeper") cp.set("dotkeeper", "base_dir", base_dir) with open(config_file, "w") as f: cp.write(f) add_to_index(config_file, git_dir=GIT_DIR) root_tree = write_tree(git_dir=GIT_DIR) print("root_tree is %r" % root_tree) commit_hash = commit_tree(root_tree, "Initial commit", parent=None, git_dir=GIT_DIR) print("commit_hash is %r" % commit_hash) git_helper(["update-ref", "HEAD", commit_hash], git_dir=GIT_DIR) print("Done!")
def cmd_commit(msg: "Commit message" = None, verbose: "Be verbose" = False): "Commits the index" tree = write_tree(git_dir=GIT_DIR) if verbose: print("New tree is", tree) commit = commit_tree(tree, msg, git_dir=GIT_DIR) if verbose: print("New commit is", commit) git_helper(["update-ref", "HEAD", commit], git_dir=GIT_DIR)
def cmd_commit(msg:"Commit message"=None, verbose:"Be verbose"=False): "Commits the index" tree = write_tree(git_dir=GIT_DIR) if verbose: print("New tree is", tree) commit = commit_tree(tree, msg, git_dir=GIT_DIR) if verbose: print("New commit is", commit) git_helper(["update-ref", "HEAD", commit], git_dir=GIT_DIR)
def cmd_log(): "Outputs a git log" global GIT_DIR git_helper(["log"], git_dir=GIT_DIR)