Skip to content
Snippets Groups Projects
Verified Commit cc1bbdac authored by René Fritze's avatar René Fritze
Browse files

transform gitsuper mechanism to be per system user

The user can now opt-into this system by creating a git repo at
$HOME/.local/share/dxt/gitsuper
parent c0b1735f
No related branches found
No related tags found
No related merge requests found
......@@ -8,10 +8,13 @@ from pathlib import Path
import subprocess
from configparser import ConfigParser
from functools import partial
import logging
get_output = partial(subprocess.check_output, universal_newlines=True)
root = Path(get_output(['git', 'rev-parse', '--show-toplevel']).strip())
supermod = Path(root, '..')
supermod_name = supermod.resolve().parts[-1]
modfile_fn = root / '.gitsuper'
......@@ -23,6 +26,20 @@ def get_env(mod):
return env
def _save_config(super, mod, cf):
target_dir = Path(os.path.expandvars('$HOME')) / '.local' / 'share' / 'dxt' / 'gitsuper'
if not target_dir.is_dir():
logging.error('Not a directory {}, skipping gitsuper committing'.format(target_dir))
return
target = target_dir / mod
os.chdir(target_dir)
env = get_env(target_dir)
with open(target, 'wt') as out:
cf.write(out)
subprocess.check_output(['git', 'add', str(target)], env=env)
subprocess.check_output(['git', 'commit', '-m', '"Updated {} from {}"'.format(mod, super)], env=env)
def for_module(cf, mod, section=None):
mod = mod.resolve()
os.chdir(mod)
......@@ -38,6 +55,8 @@ def for_module(cf, mod, section=None):
except subprocess.CalledProcessError:
pass
cf.set(section, 'commit', commit)
return cf
cf = ConfigParser()
for_module(cf, supermod, 'supermodule')
......@@ -46,7 +65,5 @@ for s in [Path(s) for s in
get_output(['git', 'submodule', '--quiet', 'foreach', 'pwd'],
env=get_env(supermod)).split()]:
for_module(cf, s)
cf.write(open(modfile_fn, 'wt'))
_save_config(supermod_name, root.parts[-1], cf)
os.chdir(root)
subprocess.check_call(['git', 'add', str(modfile_fn)])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment