summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorryneeverett <ryneeverett@gmail.com>2020-03-27 21:10:48 +0000
committerryneeverett <ryneeverett@gmail.com>2020-04-01 14:30:23 +0000
commitdf0db1774050f3e7f585e8902148a312f07b364e (patch)
tree8e2128f7197d3ed70bd0128142a045d070fcfd5f
parent9157ff4e746140960ff554ccd6fd4cf4284dba4a (diff)
vimPlugins: automatically commit update
-rw-r--r--doc/languages-frameworks/vim.section.md2
-rwxr-xr-xpkgs/misc/vim-plugins/update.py36
2 files changed, 30 insertions, 8 deletions
diff --git a/doc/languages-frameworks/vim.section.md b/doc/languages-frameworks/vim.section.md
index 05a23d26cf2f..4272d1f59691 100644
--- a/doc/languages-frameworks/vim.section.md
+++ b/doc/languages-frameworks/vim.section.md
@@ -263,7 +263,7 @@ Sometimes plugins require an override that must be changed when the plugin is up
To add a new plugin:
- 1. run `./update.py` and create a commit named "vimPlugins: Update",
+ 1. run `./update.py --commit`,
2. add the new plugin to [vim-plugin-names](/pkgs/misc/vim-plugins/vim-plugin-names) and add overrides if required to [overrides.nix](/pkgs/misc/vim-plugins/overrides.nix),
3. run `./update.py` again and create a commit named "vimPlugins.[name]: init at [version]" (where `name` and `version` can be found in [generated.nix](/pkgs/misc/vim-plugins/generated.nix)), and
4. create a pull request.
diff --git a/pkgs/misc/vim-plugins/update.py b/pkgs/misc/vim-plugins/update.py
index 0055e8eccbce..dda96816bb81 100755
--- a/pkgs/misc/vim-plugins/update.py
+++ b/pkgs/misc/vim-plugins/update.py
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
-#!nix-shell -p nix-prefetch-git -p python3 nix -i python3
+#!nix-shell -p nix-prefetch-git -p python3 -p python3Packages.GitPython nix -i python3
# format:
# $ nix run nixpkgs.python3Packages.black -c black update.py
@@ -27,11 +27,14 @@ from typing import Dict, List, Optional, Tuple, Union, Any, Callable
from urllib.parse import urljoin, urlparse
from tempfile import NamedTemporaryFile
+import git
+
ATOM_ENTRY = "{http://www.w3.org/2005/Atom}entry" # " vim gets confused here
ATOM_LINK = "{http://www.w3.org/2005/Atom}link" # "
ATOM_UPDATED = "{http://www.w3.org/2005/Atom}updated" # "
ROOT = Path(__file__).parent
+NIXPKGS_PATH = ROOT.cwd().parents[2]
DEFAULT_IN = ROOT.joinpath("vim-plugin-names")
DEFAULT_OUT = ROOT.joinpath("generated.nix")
DEPRECATED = ROOT.joinpath("deprecated.json")
@@ -413,6 +416,11 @@ in lib.fix' (lib.extends overrides packages)
print(f"updated {outfile}")
+def commit_changes(repo: git.Repo, *files: Path):
+ repo.index.add([str(f.resolve()) for f in files])
+ repo.index.commit("vimPlugins: Update")
+
+
def rewrite_input(input_file: Path, output_file: Path, redirects: dict):
with open(input_file, "r") as f:
lines = f.readlines()
@@ -438,13 +446,10 @@ def rewrite_input(input_file: Path, output_file: Path, redirects: dict):
f"""\
Redirects have been detected and {input_file} has been updated. Please take the
following steps:
- 1. Go ahead and commit just the updated expressions as you intended to do:
- git add {output_file}
- git commit -m "vimPlugins: Update"
- 2. Run this script again so these changes will be reflected in the
+ 1. Run this script again so these changes will be reflected in the
generated expressions:
./update.py
- 3. Commit {input_file} along with deprecations and generated expressions:
+ 2. Commit {input_file} along with deprecations and generated expressions:
git add {output_file} {input_file} {DEPRECATED}
git commit -m "vimPlugins: Update redirects"
"""
@@ -485,13 +490,27 @@ def parse_args():
default=30,
help="Number of concurrent processes to spawn.",
)
+ parser.add_argument(
+ "--commit",
+ dest="commit",
+ action="store_true",
+ help="Automatically commit updates",
+ )
return parser.parse_args()
-def main() -> None:
+def get_nixpkgs_repo() -> git.Repo:
+ repo = git.Repo(NIXPKGS_PATH)
+ if repo.is_dirty():
+ raise Exception("Please stash your changes before updating.")
+ return repo
+
+def main() -> None:
args = parse_args()
+ if args.commit:
+ nixpkgs_repo = get_nixpkgs_repo()
plugin_names = load_plugin_spec(args.input_file)
current_plugins = get_current_plugins()
cache = Cache(current_plugins)
@@ -510,6 +529,9 @@ def main() -> None:
rewrite_input(args.input_file, args.outfile, redirects)
+ if args.commit:
+ commit_changes(nixpkgs_repo, args.outfile)
+
if __name__ == "__main__":
main()