@kevlns/xlmerge 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +141 -141
- package/LICENSE +21 -21
- package/README.md +193 -189
- package/bin/xlmerge.js +152 -152
- package/package.json +1 -1
- package/python/xlsx_merge_engine/__init__.py +2 -2
- package/python/xlsx_merge_engine/xlsx_git_merge_bridge.py +1611 -1611
- package/python/xlsx_resolver/__init__.py +2 -2
- package/python/xlsx_resolver/__main__.py +4 -4
- package/python/xlsx_resolver/formula_values.py +565 -565
- package/python/xlsx_resolver/merge_server.py +126 -126
- package/python/xlsx_resolver/merge_ui.html +1522 -1522
- package/python/xlsx_resolver/recalculate_workbook.ps1 +155 -155
- package/python/xlsx_resolver/resolve_xlsx_conflict.py +222 -222
- package/python/xlsx_resolver/xlsx_conflict.py +1994 -1994
- package/v-cli.plugin.json +194 -194
|
@@ -1,222 +1,222 @@
|
|
|
1
|
-
"""CLI entry point for repository-local XLSX/XLSM conflict resolution."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import argparse
|
|
6
|
-
import json
|
|
7
|
-
import subprocess
|
|
8
|
-
import sys
|
|
9
|
-
import time
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
13
|
-
if str(SCRIPT_DIR) not in sys.path:
|
|
14
|
-
sys.path.insert(0, str(SCRIPT_DIR))
|
|
15
|
-
|
|
16
|
-
from xlsx_conflict import (
|
|
17
|
-
ConflictError,
|
|
18
|
-
add_auto_theirs_filter,
|
|
19
|
-
apply_manifest,
|
|
20
|
-
auto_theirs_path,
|
|
21
|
-
detect_conflicts,
|
|
22
|
-
find_repo_root,
|
|
23
|
-
load_manifest,
|
|
24
|
-
load_auto_theirs_filters,
|
|
25
|
-
prepare_conflicts,
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
SCRIPT_PATH = Path(__file__).resolve()
|
|
30
|
-
PACKAGE_ROOT = SCRIPT_DIR.parent
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _configure_stdio() -> None:
|
|
34
|
-
"""Keep structured CLI output UTF-8 even under legacy Windows code pages."""
|
|
35
|
-
for stream in (sys.stdout, sys.stderr):
|
|
36
|
-
reconfigure = getattr(stream, "reconfigure", None)
|
|
37
|
-
if callable(reconfigure):
|
|
38
|
-
reconfigure(encoding="utf-8", errors="replace")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def _print(data) -> None:
|
|
42
|
-
print(json.dumps(data, ensure_ascii=False, indent=2))
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _launch_background(repo: Path, manifest: Path, *, open_browser: bool) -> dict:
|
|
46
|
-
"""Start the resolver as a detached child and return its URL promptly."""
|
|
47
|
-
runtime_dir = manifest.parent
|
|
48
|
-
stamp = int(time.time() * 1000)
|
|
49
|
-
stdout_path = runtime_dir / f"resolver-{stamp}.stdout.log"
|
|
50
|
-
stderr_path = runtime_dir / f"resolver-{stamp}.stderr.log"
|
|
51
|
-
command = [
|
|
52
|
-
sys.executable,
|
|
53
|
-
str(SCRIPT_PATH),
|
|
54
|
-
"--repo",
|
|
55
|
-
str(repo),
|
|
56
|
-
"serve",
|
|
57
|
-
"--manifest",
|
|
58
|
-
str(manifest),
|
|
59
|
-
]
|
|
60
|
-
if not open_browser:
|
|
61
|
-
command.append("--no-browser")
|
|
62
|
-
creationflags = (
|
|
63
|
-
getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
|
64
|
-
| getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
|
|
65
|
-
)
|
|
66
|
-
with stdout_path.open("w", encoding="utf-8") as stdout_handle, stderr_path.open("w", encoding="utf-8") as stderr_handle:
|
|
67
|
-
process = subprocess.Popen(
|
|
68
|
-
command,
|
|
69
|
-
cwd=str(PACKAGE_ROOT),
|
|
70
|
-
stdout=stdout_handle,
|
|
71
|
-
stderr=stderr_handle,
|
|
72
|
-
stdin=subprocess.DEVNULL,
|
|
73
|
-
creationflags=creationflags,
|
|
74
|
-
close_fds=True,
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
deadline = time.monotonic() + 15
|
|
78
|
-
url = ""
|
|
79
|
-
while time.monotonic() < deadline:
|
|
80
|
-
output = stdout_path.read_text(encoding="utf-8", errors="replace") if stdout_path.exists() else ""
|
|
81
|
-
for line in output.splitlines():
|
|
82
|
-
if line.startswith("MERGE_SERVER_URL="):
|
|
83
|
-
url = line.split("=", 1)[1].strip()
|
|
84
|
-
break
|
|
85
|
-
if url or process.poll() is not None:
|
|
86
|
-
break
|
|
87
|
-
time.sleep(0.1)
|
|
88
|
-
|
|
89
|
-
if not url:
|
|
90
|
-
if process.poll() is None:
|
|
91
|
-
process.terminate()
|
|
92
|
-
stderr = stderr_path.read_text(encoding="utf-8", errors="replace") if stderr_path.exists() else ""
|
|
93
|
-
raise ConflictError(f"Resolver failed to start: {stderr.strip() or 'URL was not reported within 15 seconds'}")
|
|
94
|
-
return {
|
|
95
|
-
"ok": True,
|
|
96
|
-
"pid": process.pid,
|
|
97
|
-
"url": url,
|
|
98
|
-
"manifest": str(manifest),
|
|
99
|
-
"stdout": str(stdout_path),
|
|
100
|
-
"stderr": str(stderr_path),
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def _auto_only(manifest: Path) -> dict | None:
|
|
105
|
-
"""Resolve an all-auto-theirs manifest immediately instead of starting an empty UI."""
|
|
106
|
-
if load_manifest(manifest)["files"]:
|
|
107
|
-
return None
|
|
108
|
-
result = apply_manifest(manifest, {"files": {}})
|
|
109
|
-
return {
|
|
110
|
-
"ok": result["success"],
|
|
111
|
-
"url": None,
|
|
112
|
-
"manifest": str(manifest),
|
|
113
|
-
"autoResolved": result.get("autoTheirs", []),
|
|
114
|
-
"steps": result["steps"],
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def build_parser() -> argparse.ArgumentParser:
|
|
119
|
-
parser = argparse.ArgumentParser(description="Resolve Git XLSX/XLSM conflicts in a Git repository.")
|
|
120
|
-
parser.add_argument("--repo", default=".", help="Git repository (default: %(default)s; the current directory).")
|
|
121
|
-
parser.add_argument("--runtime-dir", help="Optional directory for extracted Git stage workbooks and manifest.")
|
|
122
|
-
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
123
|
-
|
|
124
|
-
subparsers.add_parser("detect", help="List unresolved .xlsx/.xlsm files.")
|
|
125
|
-
|
|
126
|
-
filter_parser = subparsers.add_parser("filter", help="Manage repository-scoped auto-theirs workbook filters.")
|
|
127
|
-
filter_subparsers = filter_parser.add_subparsers(dest="filter_command", required=True)
|
|
128
|
-
filter_add = filter_subparsers.add_parser("add", help="Add one case-insensitive workbook path-suffix filter.")
|
|
129
|
-
filter_add.add_argument("path", help="Relative .xlsx/.xlsm path suffix to adopt from Git stage 3.")
|
|
130
|
-
|
|
131
|
-
prepare = subparsers.add_parser("prepare", help="Extract base/ours/theirs and build a sheet-aware manifest.")
|
|
132
|
-
prepare.add_argument("--path", help="Only prepare this repository-relative .xlsx/.xlsm path.")
|
|
133
|
-
|
|
134
|
-
resolve = subparsers.add_parser("resolve", help="Prepare conflicts and launch the local visual resolver.")
|
|
135
|
-
resolve.add_argument("--path", help="Only resolve this repository-relative .xlsx/.xlsm path.")
|
|
136
|
-
resolve.add_argument("--no-browser", action="store_true", help="Print the URL without opening a browser.")
|
|
137
|
-
|
|
138
|
-
launch = subparsers.add_parser("launch", help="Prepare conflicts, start the visual resolver in background, and return its URL.")
|
|
139
|
-
launch.add_argument("--path", help="Only resolve this repository-relative .xlsx/.xlsm path.")
|
|
140
|
-
launch.add_argument("--no-browser", action="store_true", help="Start the server without opening a browser.")
|
|
141
|
-
|
|
142
|
-
serve_parser = subparsers.add_parser("serve", help=argparse.SUPPRESS)
|
|
143
|
-
serve_parser.add_argument("--manifest", required=True)
|
|
144
|
-
serve_parser.add_argument("--no-browser", action="store_true")
|
|
145
|
-
serve_parser.add_argument("--port", type=int, default=0, help="Fixed listen port (0 = ephemeral).")
|
|
146
|
-
|
|
147
|
-
apply_parser = subparsers.add_parser("apply", help="Apply a decisions JSON without launching the UI.")
|
|
148
|
-
apply_parser.add_argument("--manifest", required=True)
|
|
149
|
-
apply_parser.add_argument("--decisions", required=True)
|
|
150
|
-
apply_parser.add_argument("--no-commit", action="store_true")
|
|
151
|
-
apply_parser.add_argument("--push", action="store_true")
|
|
152
|
-
apply_parser.add_argument("--message", default=None, help="Override the auto-generated structured commit message.")
|
|
153
|
-
return parser
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def main(argv: list[str] | None = None) -> int:
|
|
157
|
-
_configure_stdio()
|
|
158
|
-
args = build_parser().parse_args(argv)
|
|
159
|
-
try:
|
|
160
|
-
# serve/apply 仅依赖 manifest(其 repoRoot 在 apply_manifest 内部解析),
|
|
161
|
-
# 可在非 git 目录下运行;其余公开命令需要前置解析仓库。
|
|
162
|
-
if args.command in ("detect", "filter", "prepare", "resolve", "launch"):
|
|
163
|
-
repo = find_repo_root(args.repo)
|
|
164
|
-
if args.command == "filter":
|
|
165
|
-
result = add_auto_theirs_filter(repo, args.path)
|
|
166
|
-
_print({"ok": True, "repo": str(repo), **result})
|
|
167
|
-
return 0
|
|
168
|
-
if args.command == "detect":
|
|
169
|
-
conflicts = detect_conflicts(repo)
|
|
170
|
-
filters = load_auto_theirs_filters(repo)
|
|
171
|
-
auto = [item["path"] for item in conflicts if auto_theirs_path(item["path"], filters)]
|
|
172
|
-
_print({
|
|
173
|
-
"ok": True,
|
|
174
|
-
"repo": str(repo),
|
|
175
|
-
"count": len(conflicts),
|
|
176
|
-
"reviewCount": len(conflicts) - len(auto),
|
|
177
|
-
"autoTheirs": auto,
|
|
178
|
-
"conflicts": conflicts,
|
|
179
|
-
})
|
|
180
|
-
return 0
|
|
181
|
-
if args.command == "prepare":
|
|
182
|
-
manifest = prepare_conflicts(repo, relative_path=args.path, runtime_dir=args.runtime_dir)
|
|
183
|
-
_print({"ok": True, "manifest": str(manifest)})
|
|
184
|
-
return 0
|
|
185
|
-
if args.command == "resolve":
|
|
186
|
-
manifest = prepare_conflicts(repo, relative_path=args.path, runtime_dir=args.runtime_dir)
|
|
187
|
-
auto = _auto_only(manifest)
|
|
188
|
-
if auto is not None:
|
|
189
|
-
_print(auto)
|
|
190
|
-
return 0 if auto["ok"] else 1
|
|
191
|
-
from merge_server import serve
|
|
192
|
-
|
|
193
|
-
return 0 if serve(manifest, open_browser=not args.no_browser) else 1
|
|
194
|
-
if args.command == "launch":
|
|
195
|
-
manifest = prepare_conflicts(repo, relative_path=args.path, runtime_dir=args.runtime_dir)
|
|
196
|
-
auto = _auto_only(manifest)
|
|
197
|
-
if auto is not None:
|
|
198
|
-
_print(auto)
|
|
199
|
-
return 0 if auto["ok"] else 1
|
|
200
|
-
_print(_launch_background(repo, manifest, open_browser=not args.no_browser))
|
|
201
|
-
return 0
|
|
202
|
-
if args.command == "serve":
|
|
203
|
-
from merge_server import serve
|
|
204
|
-
|
|
205
|
-
return 0 if serve(args.manifest, open_browser=not args.no_browser, port=args.port) else 1
|
|
206
|
-
decisions = json.loads(Path(args.decisions).read_text(encoding="utf-8"))
|
|
207
|
-
result = apply_manifest(
|
|
208
|
-
args.manifest,
|
|
209
|
-
decisions,
|
|
210
|
-
commit=not args.no_commit,
|
|
211
|
-
push=args.push,
|
|
212
|
-
message=args.message,
|
|
213
|
-
)
|
|
214
|
-
_print(result)
|
|
215
|
-
return 0 if result["success"] else 1
|
|
216
|
-
except (ConflictError, OSError, ValueError, json.JSONDecodeError) as exc:
|
|
217
|
-
_print({"ok": False, "error": str(exc)})
|
|
218
|
-
return 1
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if __name__ == "__main__":
|
|
222
|
-
sys.exit(main())
|
|
1
|
+
"""CLI entry point for repository-local XLSX/XLSM conflict resolution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
13
|
+
if str(SCRIPT_DIR) not in sys.path:
|
|
14
|
+
sys.path.insert(0, str(SCRIPT_DIR))
|
|
15
|
+
|
|
16
|
+
from xlsx_conflict import (
|
|
17
|
+
ConflictError,
|
|
18
|
+
add_auto_theirs_filter,
|
|
19
|
+
apply_manifest,
|
|
20
|
+
auto_theirs_path,
|
|
21
|
+
detect_conflicts,
|
|
22
|
+
find_repo_root,
|
|
23
|
+
load_manifest,
|
|
24
|
+
load_auto_theirs_filters,
|
|
25
|
+
prepare_conflicts,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
SCRIPT_PATH = Path(__file__).resolve()
|
|
30
|
+
PACKAGE_ROOT = SCRIPT_DIR.parent
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _configure_stdio() -> None:
|
|
34
|
+
"""Keep structured CLI output UTF-8 even under legacy Windows code pages."""
|
|
35
|
+
for stream in (sys.stdout, sys.stderr):
|
|
36
|
+
reconfigure = getattr(stream, "reconfigure", None)
|
|
37
|
+
if callable(reconfigure):
|
|
38
|
+
reconfigure(encoding="utf-8", errors="replace")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _print(data) -> None:
|
|
42
|
+
print(json.dumps(data, ensure_ascii=False, indent=2))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _launch_background(repo: Path, manifest: Path, *, open_browser: bool) -> dict:
|
|
46
|
+
"""Start the resolver as a detached child and return its URL promptly."""
|
|
47
|
+
runtime_dir = manifest.parent
|
|
48
|
+
stamp = int(time.time() * 1000)
|
|
49
|
+
stdout_path = runtime_dir / f"resolver-{stamp}.stdout.log"
|
|
50
|
+
stderr_path = runtime_dir / f"resolver-{stamp}.stderr.log"
|
|
51
|
+
command = [
|
|
52
|
+
sys.executable,
|
|
53
|
+
str(SCRIPT_PATH),
|
|
54
|
+
"--repo",
|
|
55
|
+
str(repo),
|
|
56
|
+
"serve",
|
|
57
|
+
"--manifest",
|
|
58
|
+
str(manifest),
|
|
59
|
+
]
|
|
60
|
+
if not open_browser:
|
|
61
|
+
command.append("--no-browser")
|
|
62
|
+
creationflags = (
|
|
63
|
+
getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
|
64
|
+
| getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
|
|
65
|
+
)
|
|
66
|
+
with stdout_path.open("w", encoding="utf-8") as stdout_handle, stderr_path.open("w", encoding="utf-8") as stderr_handle:
|
|
67
|
+
process = subprocess.Popen(
|
|
68
|
+
command,
|
|
69
|
+
cwd=str(PACKAGE_ROOT),
|
|
70
|
+
stdout=stdout_handle,
|
|
71
|
+
stderr=stderr_handle,
|
|
72
|
+
stdin=subprocess.DEVNULL,
|
|
73
|
+
creationflags=creationflags,
|
|
74
|
+
close_fds=True,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
deadline = time.monotonic() + 15
|
|
78
|
+
url = ""
|
|
79
|
+
while time.monotonic() < deadline:
|
|
80
|
+
output = stdout_path.read_text(encoding="utf-8", errors="replace") if stdout_path.exists() else ""
|
|
81
|
+
for line in output.splitlines():
|
|
82
|
+
if line.startswith("MERGE_SERVER_URL="):
|
|
83
|
+
url = line.split("=", 1)[1].strip()
|
|
84
|
+
break
|
|
85
|
+
if url or process.poll() is not None:
|
|
86
|
+
break
|
|
87
|
+
time.sleep(0.1)
|
|
88
|
+
|
|
89
|
+
if not url:
|
|
90
|
+
if process.poll() is None:
|
|
91
|
+
process.terminate()
|
|
92
|
+
stderr = stderr_path.read_text(encoding="utf-8", errors="replace") if stderr_path.exists() else ""
|
|
93
|
+
raise ConflictError(f"Resolver failed to start: {stderr.strip() or 'URL was not reported within 15 seconds'}")
|
|
94
|
+
return {
|
|
95
|
+
"ok": True,
|
|
96
|
+
"pid": process.pid,
|
|
97
|
+
"url": url,
|
|
98
|
+
"manifest": str(manifest),
|
|
99
|
+
"stdout": str(stdout_path),
|
|
100
|
+
"stderr": str(stderr_path),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _auto_only(manifest: Path) -> dict | None:
|
|
105
|
+
"""Resolve an all-auto-theirs manifest immediately instead of starting an empty UI."""
|
|
106
|
+
if load_manifest(manifest)["files"]:
|
|
107
|
+
return None
|
|
108
|
+
result = apply_manifest(manifest, {"files": {}})
|
|
109
|
+
return {
|
|
110
|
+
"ok": result["success"],
|
|
111
|
+
"url": None,
|
|
112
|
+
"manifest": str(manifest),
|
|
113
|
+
"autoResolved": result.get("autoTheirs", []),
|
|
114
|
+
"steps": result["steps"],
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
119
|
+
parser = argparse.ArgumentParser(description="Resolve Git XLSX/XLSM conflicts in a Git repository.")
|
|
120
|
+
parser.add_argument("--repo", default=".", help="Git repository (default: %(default)s; the current directory).")
|
|
121
|
+
parser.add_argument("--runtime-dir", help="Optional directory for extracted Git stage workbooks and manifest.")
|
|
122
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
123
|
+
|
|
124
|
+
subparsers.add_parser("detect", help="List unresolved .xlsx/.xlsm files.")
|
|
125
|
+
|
|
126
|
+
filter_parser = subparsers.add_parser("filter", help="Manage repository-scoped auto-theirs workbook filters.")
|
|
127
|
+
filter_subparsers = filter_parser.add_subparsers(dest="filter_command", required=True)
|
|
128
|
+
filter_add = filter_subparsers.add_parser("add", help="Add one case-insensitive workbook path-suffix filter.")
|
|
129
|
+
filter_add.add_argument("path", help="Relative .xlsx/.xlsm path suffix to adopt from Git stage 3.")
|
|
130
|
+
|
|
131
|
+
prepare = subparsers.add_parser("prepare", help="Extract base/ours/theirs and build a sheet-aware manifest.")
|
|
132
|
+
prepare.add_argument("--path", help="Only prepare this repository-relative .xlsx/.xlsm path.")
|
|
133
|
+
|
|
134
|
+
resolve = subparsers.add_parser("resolve", help="Prepare conflicts and launch the local visual resolver.")
|
|
135
|
+
resolve.add_argument("--path", help="Only resolve this repository-relative .xlsx/.xlsm path.")
|
|
136
|
+
resolve.add_argument("--no-browser", action="store_true", help="Print the URL without opening a browser.")
|
|
137
|
+
|
|
138
|
+
launch = subparsers.add_parser("launch", help="Prepare conflicts, start the visual resolver in background, and return its URL.")
|
|
139
|
+
launch.add_argument("--path", help="Only resolve this repository-relative .xlsx/.xlsm path.")
|
|
140
|
+
launch.add_argument("--no-browser", action="store_true", help="Start the server without opening a browser.")
|
|
141
|
+
|
|
142
|
+
serve_parser = subparsers.add_parser("serve", help=argparse.SUPPRESS)
|
|
143
|
+
serve_parser.add_argument("--manifest", required=True)
|
|
144
|
+
serve_parser.add_argument("--no-browser", action="store_true")
|
|
145
|
+
serve_parser.add_argument("--port", type=int, default=0, help="Fixed listen port (0 = ephemeral).")
|
|
146
|
+
|
|
147
|
+
apply_parser = subparsers.add_parser("apply", help="Apply a decisions JSON without launching the UI.")
|
|
148
|
+
apply_parser.add_argument("--manifest", required=True)
|
|
149
|
+
apply_parser.add_argument("--decisions", required=True)
|
|
150
|
+
apply_parser.add_argument("--no-commit", action="store_true")
|
|
151
|
+
apply_parser.add_argument("--push", action="store_true")
|
|
152
|
+
apply_parser.add_argument("--message", default=None, help="Override the auto-generated structured commit message.")
|
|
153
|
+
return parser
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def main(argv: list[str] | None = None) -> int:
|
|
157
|
+
_configure_stdio()
|
|
158
|
+
args = build_parser().parse_args(argv)
|
|
159
|
+
try:
|
|
160
|
+
# serve/apply 仅依赖 manifest(其 repoRoot 在 apply_manifest 内部解析),
|
|
161
|
+
# 可在非 git 目录下运行;其余公开命令需要前置解析仓库。
|
|
162
|
+
if args.command in ("detect", "filter", "prepare", "resolve", "launch"):
|
|
163
|
+
repo = find_repo_root(args.repo)
|
|
164
|
+
if args.command == "filter":
|
|
165
|
+
result = add_auto_theirs_filter(repo, args.path)
|
|
166
|
+
_print({"ok": True, "repo": str(repo), **result})
|
|
167
|
+
return 0
|
|
168
|
+
if args.command == "detect":
|
|
169
|
+
conflicts = detect_conflicts(repo)
|
|
170
|
+
filters = load_auto_theirs_filters(repo)
|
|
171
|
+
auto = [item["path"] for item in conflicts if auto_theirs_path(item["path"], filters)]
|
|
172
|
+
_print({
|
|
173
|
+
"ok": True,
|
|
174
|
+
"repo": str(repo),
|
|
175
|
+
"count": len(conflicts),
|
|
176
|
+
"reviewCount": len(conflicts) - len(auto),
|
|
177
|
+
"autoTheirs": auto,
|
|
178
|
+
"conflicts": conflicts,
|
|
179
|
+
})
|
|
180
|
+
return 0
|
|
181
|
+
if args.command == "prepare":
|
|
182
|
+
manifest = prepare_conflicts(repo, relative_path=args.path, runtime_dir=args.runtime_dir)
|
|
183
|
+
_print({"ok": True, "manifest": str(manifest)})
|
|
184
|
+
return 0
|
|
185
|
+
if args.command == "resolve":
|
|
186
|
+
manifest = prepare_conflicts(repo, relative_path=args.path, runtime_dir=args.runtime_dir)
|
|
187
|
+
auto = _auto_only(manifest)
|
|
188
|
+
if auto is not None:
|
|
189
|
+
_print(auto)
|
|
190
|
+
return 0 if auto["ok"] else 1
|
|
191
|
+
from merge_server import serve
|
|
192
|
+
|
|
193
|
+
return 0 if serve(manifest, open_browser=not args.no_browser) else 1
|
|
194
|
+
if args.command == "launch":
|
|
195
|
+
manifest = prepare_conflicts(repo, relative_path=args.path, runtime_dir=args.runtime_dir)
|
|
196
|
+
auto = _auto_only(manifest)
|
|
197
|
+
if auto is not None:
|
|
198
|
+
_print(auto)
|
|
199
|
+
return 0 if auto["ok"] else 1
|
|
200
|
+
_print(_launch_background(repo, manifest, open_browser=not args.no_browser))
|
|
201
|
+
return 0
|
|
202
|
+
if args.command == "serve":
|
|
203
|
+
from merge_server import serve
|
|
204
|
+
|
|
205
|
+
return 0 if serve(args.manifest, open_browser=not args.no_browser, port=args.port) else 1
|
|
206
|
+
decisions = json.loads(Path(args.decisions).read_text(encoding="utf-8"))
|
|
207
|
+
result = apply_manifest(
|
|
208
|
+
args.manifest,
|
|
209
|
+
decisions,
|
|
210
|
+
commit=not args.no_commit,
|
|
211
|
+
push=args.push,
|
|
212
|
+
message=args.message,
|
|
213
|
+
)
|
|
214
|
+
_print(result)
|
|
215
|
+
return 0 if result["success"] else 1
|
|
216
|
+
except (ConflictError, OSError, ValueError, json.JSONDecodeError) as exc:
|
|
217
|
+
_print({"ok": False, "error": str(exc)})
|
|
218
|
+
return 1
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
if __name__ == "__main__":
|
|
222
|
+
sys.exit(main())
|