diff options
author | Alexandru Fikl <alexfikl@gmail.com> | 2024-04-24 11:48:44 +0300 |
---|---|---|
committer | Alex Fikl <alexfikl@gmail.com> | 2024-04-25 18:49:18 +0300 |
commit | 3fbaa731adcc1bc9a45ecb12b9baec0ae1af1a77 (patch) | |
tree | a7a33b948c88a6d42fdd4413dffae2ccdfe307aa | |
parent | d50e7d452df381a6f3afe83982a8a04247e94338 (diff) |
commands.init: initialize a git repository
-rw-r--r-- | papis/commands/init.py | 8 | ||||
-rw-r--r-- | papis/git.py | 7 | ||||
-rw-r--r-- | papis/paths.py | 2 |
3 files changed, 16 insertions, 1 deletions
diff --git a/papis/commands/init.py b/papis/commands/init.py index f88b9b6e..f680af31 100644 --- a/papis/commands/init.py +++ b/papis/commands/init.py @@ -174,6 +174,14 @@ def cli(dir_path: Optional[str]) -> None: default=str(local.get(setting, defaults.get(setting))), bottom_toolbar=help_string) + use_git = papis.config.getboolean("use-git", section=library_name) + if use_git and not _is_git_repository(library_path): + if confirm(f"Library '{library_path}' is not a git repository and 'use-git' " + "is enabled. Would you like to initialize a git repository?"): + papis.git.init(library_path) + papis.git.add(library_path, ".") + papis.git.commit(library_path, f"Initialized library '{library_name}'") + if confirm("Do you want to save?"): config_folder = papis.config.get_config_folder() if not os.path.exists(config_folder): diff --git a/papis/git.py b/papis/git.py index 47ae7180..19857f4d 100644 --- a/papis/git.py +++ b/papis/git.py @@ -9,6 +9,13 @@ import papis.logging logger = papis.logging.get_logger(__name__) +def init(path: str) -> None: + """Initialize a git repository at *path*.""" + + logger.info("Initializing git repository: '%s'.", path) + papis.utils.run(["git", "init"], cwd=path) + + def add(path: str, resource: str) -> None: """Adds changes in the *path* to the git index with a *message*. diff --git a/papis/paths.py b/papis/paths.py index 9c9b3fce..90445eba 100644 --- a/papis/paths.py +++ b/papis/paths.py @@ -117,7 +117,7 @@ def symlink(src: PathLike, dst: PathLike) -> None: This is a simple wrapper around :func:`os.symlink` that attempts to give better error messages on different platforms. For example, it offers - suggestions for some missing priviledge issues. + suggestions for some missing privilege issues. :param src: the existing file that *dst* points to. :param dst: the name of the new symbolic link, pointing to *src*. |