mirror of
https://github.com/elliotnunn/supermario.git
synced 2024-11-26 01:49:19 +00:00
Simplify deepen/flatten scripts
They no longer try and fail to work with existing git repositories. If an existing one gets in the way, it gets trashed and reinitialized.
This commit is contained in:
parent
5f460e9e1b
commit
36a2454343
44
bin/deepen
44
bin/deepen
@ -23,8 +23,6 @@ parser.add_argument('patchset', metavar='PATCHSET', action='store', type=lambda
|
|||||||
parser.add_argument('worktree', metavar='WORKTREE', action='store', type=lambda x: folder('worktree', x), help='Destination worktree (assumed in ../worktree/)')
|
parser.add_argument('worktree', metavar='WORKTREE', action='store', type=lambda x: folder('worktree', x), help='Destination worktree (assumed in ../worktree/)')
|
||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
group.add_argument('--base', metavar='SRC', action='store', default='SuperMarioProj.1994-02-09', type=lambda x: folder('base', x), help='Base source tree (default=SuperMarioProj.1994-02-09, assumed in ../base/)')
|
group.add_argument('--base', metavar='SRC', action='store', default='SuperMarioProj.1994-02-09', type=lambda x: folder('base', x), help='Base source tree (default=SuperMarioProj.1994-02-09, assumed in ../base/)')
|
||||||
group.add_argument('--base-commit', metavar='REV', action='store', help='Base commit')
|
|
||||||
parser.add_argument('--branch', metavar='BRANCH', action='store', default='master', help='Destination branch')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -34,25 +32,23 @@ assert not path.exists(path.join(args.patchset, '.git')) # protect against argum
|
|||||||
|
|
||||||
|
|
||||||
horst = ['-c', 'user.name=Horst Beepmanh', '-c', 'user.email=<>']
|
horst = ['-c', 'user.name=Horst Beepmanh', '-c', 'user.email=<>']
|
||||||
|
def git(*gitargs):
|
||||||
|
run(['git', *horst, *gitargs], cwd=args.worktree, check=True)
|
||||||
|
|
||||||
|
|
||||||
makedirs(args.worktree, exist_ok=True)
|
|
||||||
run(['git', 'init'], cwd=args.worktree, check=True)
|
|
||||||
run(['git', 'checkout', '--orphan', args.branch], cwd=args.worktree, check=True)
|
|
||||||
|
|
||||||
# This cleans the working directory, because the manpage's suggestion `git rm -rf .` does not work
|
|
||||||
run(['git', 'reset'], cwd=args.worktree, check=True)
|
|
||||||
for do_delete in listdir(args.worktree):
|
|
||||||
if do_delete != '.git':
|
|
||||||
do_delete = path.join(args.worktree, do_delete)
|
|
||||||
try:
|
try:
|
||||||
rmtree(do_delete)
|
rmtree(args.worktree)
|
||||||
except NotADirectoryError:
|
except FileNotFoundError:
|
||||||
remove(do_delete)
|
pass
|
||||||
|
makedirs(args.worktree)
|
||||||
|
|
||||||
|
with open(path.join(args.worktree, '.gitignore'), 'a') as f:
|
||||||
|
f.write('.*\n*.dmg\nBuild*/\n')
|
||||||
|
|
||||||
|
git('init')
|
||||||
|
git('add', '-f', '.gitignore')
|
||||||
|
git('commit', '-m', 'Useful non-source things')
|
||||||
|
|
||||||
if args.base_commit is not None:
|
|
||||||
run(['git', 'reset', '--hard', args.base_commit], cwd=args.worktree, check=True)
|
|
||||||
else:
|
|
||||||
for walk_base, walk_dirs, walk_files in walk(args.base):
|
for walk_base, walk_dirs, walk_files in walk(args.base):
|
||||||
walk_dirs[:] = [x for x in walk_dirs if not x.startswith('.')]
|
walk_dirs[:] = [x for x in walk_dirs if not x.startswith('.')]
|
||||||
walk_files[:] = [x for x in walk_files if not x.startswith('.')]
|
walk_files[:] = [x for x in walk_files if not x.startswith('.')]
|
||||||
@ -64,15 +60,9 @@ else:
|
|||||||
for this_file in walk_files:
|
for this_file in walk_files:
|
||||||
copy(path.join(walk_base, this_file), other_dir)
|
copy(path.join(walk_base, this_file), other_dir)
|
||||||
|
|
||||||
run(['git', 'add', '.'], cwd=args.worktree, check=True)
|
git('add', '.')
|
||||||
run(['git', *horst, 'commit', '-m', path.basename(args.base)], cwd=args.worktree, check=True)
|
git('commit', '-m', path.basename(args.base))
|
||||||
|
git('tag', 'patchset-base')
|
||||||
with open(path.join(args.worktree, '.gitignore'), 'a') as f:
|
|
||||||
f.write('Build*\n')
|
|
||||||
run(['git', 'add', '.gitignore'], cwd=args.worktree, check=True)
|
|
||||||
run(['git', *horst, 'commit', '-m', 'auto-gitignore (do not rebase)'], cwd=args.worktree, check=True)
|
|
||||||
|
|
||||||
run(['git', 'tag', args.branch+'-patchset-base'], cwd=args.worktree, check=True)
|
|
||||||
|
|
||||||
patchfiles = [path.join(args.patchset, x) for x in sorted(listdir(args.patchset)) if path.splitext(x)[1].lower() == '.patch']
|
patchfiles = [path.join(args.patchset, x) for x in sorted(listdir(args.patchset)) if path.splitext(x)[1].lower() == '.patch']
|
||||||
run(['git', *horst, 'am', *patchfiles], cwd=args.worktree, check=True)
|
git('am', *patchfiles)
|
||||||
|
@ -40,7 +40,7 @@ for do_delete in listdir(args.patchset):
|
|||||||
remove(do_delete)
|
remove(do_delete)
|
||||||
|
|
||||||
|
|
||||||
run(['git', 'format-patch', '-o', args.patchset, '--anchored=;', 'master-patchset-base'], stdout=DEVNULL, cwd=args.worktree, check=True)
|
run(['git', 'format-patch', '-o', args.patchset, '--anchored=;', 'patchset-base'], stdout=DEVNULL, cwd=args.worktree, check=True)
|
||||||
|
|
||||||
if args.raw: exit()
|
if args.raw: exit()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user