-
Notifications
You must be signed in to change notification settings - Fork 7
/
bzr_split_folder
executable file
·76 lines (61 loc) · 2.4 KB
/
bzr_split_folder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# coding: utf-8
import misc
import os
import bzrlib.workingtree
import sys
# To run this script:
# python bzr_split_folder path_file_bzr_to_made_git name_module
# Sample
# python bzr_split_folder /User/myUser/Instancia/6.1/addons/oml2 l10n_mx_facturae
bzr_branch = sys.argv[1]
folders_to_split = sys.argv[2].split(',')
bzr_branch_splitted = os.path.join(bzr_branch, 'splitted')
#Make new main branch
misc.mkdirs(bzr_branch_splitted)
cmd = ['bzr', 'init']
misc.run_output(cmd, cwd=bzr_branch_splitted)
# Get full log history from branch
fname_full_history = os.path.join(bzr_branch, 'full-history.fi')
open(fname_full_history, "w").write(
misc.run_output(["bzr", "fast-export"], cwd=bzr_branch))
for folder_to_split in folders_to_split:
# Get log filter to folder
fname_folder_history = os.path.join(bzr_branch,
folder_to_split + '.fi')
cmd = ["bzr", "fast-import-filter", "-i",
folder_to_split, fname_full_history]
open(fname_folder_history, "w").write(
misc.run_output(cmd, cwd=bzr_branch))
# Make new branch
path_folder_split = os.path.join(bzr_branch_splitted,
folder_to_split + '_to_join')
misc.mkdirs(path_folder_split)
cmd = ['bzr', 'init']
misc.run_output(cmd, cwd=path_folder_split)
# Import all filter commit from folder to new branch
cmd = ['bzr', 'fast-import', fname_folder_history]
misc.run_output(cmd, cwd=path_folder_split)
# Fixing join error more info here
# https://answers.launchpad.net/bzr/+question/71563
bzrlib.workingtree.WorkingTree.open(path_folder_split).\
set_root_id("tree_root_" + folder_to_split)
# Run join command
cmd = ['bzr', 'join', path_folder_split]
misc.run_output(cmd, cwd=bzr_branch_splitted)
# Commit of join
cmd = ['bzr', 'commit', '-m', 'Join commit']
misc.run_output(cmd, cwd=bzr_branch_splitted)
# Move joinned folder to root path
cmd = ['bzr', 'mv',
os.path.join(path_folder_split, folder_to_split),
bzr_branch_splitted]
misc.run(cmd)
# Remove unused path
cmd = ['bzr', 'rm', path_folder_split]
misc.run(cmd)
# Commit of mv
cmd = ['bzr', 'commit', '-m', 'Move to root path']
misc.run_output(cmd, cwd=bzr_branch_splitted)
sys.stdout.write('Now you can check next branch: ' +
bzr_branch_splitted + '\n')