Skip to content

Commit 6d79ed9

Browse files
akoclaude
andcommitted
refactor: simplify diff-local to accept git ranges via --ref directly
Remove --base flag per review feedback. Git range syntax (main..feature, main...feature) can be passed directly to --ref. The parseRefRange() helper in the executor splits the range for git show on each side. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5a5e470 commit 6d79ed9

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ go build -o bin/mxcli ./cmd/mxcli
334334
| **Testing** | `mxcli test tests/ -p app.mpr` | `.test.mdl` / `.test.md` files, requires Docker |
335335
| **Diff** | `mxcli diff -p app.mpr changes.mdl` | Compare script against project state |
336336
| **Diff local** | `mxcli diff-local -p app.mpr --ref HEAD` | Git diff for MPR v2 projects |
337-
| **Diff revisions** | `mxcli diff-local -p app.mpr --base main --ref feature` | Compare two arbitrary git revisions |
337+
| **Diff revisions** | `mxcli diff-local -p app.mpr --ref main..feature` | Compare two arbitrary git revisions |
338338
| **OQL** | `mxcli oql -p app.mpr "SELECT ..."` | Query running Mendix runtime |
339339
| **Widgets** | `SHOW WIDGETS`, `UPDATE WIDGETS SET ...` | Widget discovery and bulk updates (experimental) |
340340
| **External SQL** | `SQL CONNECT`, `SQL <alias> SELECT ...`, `mxcli sql` | Direct SQL queries against PostgreSQL, Oracle, SQL Server (credential isolation) |

cmd/mxcli/cmd_diff.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ var diffLocalCmd = &cobra.Command{
102102
This command finds modified mxunit files in the mprcontents/ folder and shows
103103
the differences as MDL. Only works with MPR v2 format (Mendix 10.18+).
104104
105-
Use --ref for single-ref comparison (working tree vs ref), or --base with --ref
106-
to compare two arbitrary revisions (e.g., main vs feature branch).
105+
The --ref flag accepts any git ref or range (e.g., HEAD, main, main..feature-branch).
107106
108107
Examples:
109108
# Show uncommitted changes vs HEAD
@@ -115,19 +114,18 @@ Examples:
115114
# Compare against a branch
116115
mxcli diff-local -p app.mpr --ref main
117116
118-
# Compare two arbitrary revisions
119-
mxcli diff-local -p app.mpr --base main --ref feature-branch
117+
# Compare two arbitrary revisions (git range syntax)
118+
mxcli diff-local -p app.mpr --ref main..feature-branch
120119
121-
# Compare two commits
122-
mxcli diff-local -p app.mpr --base abc1234 --ref def5678
120+
# Three-dot range (changes since common ancestor)
121+
mxcli diff-local -p app.mpr --ref main...feature-branch
123122
124123
# With structural format
125124
mxcli diff-local -p app.mpr --format struct --color
126125
`,
127126
Run: func(cmd *cobra.Command, args []string) {
128127
projectPath, _ := cmd.Flags().GetString("project")
129128
ref, _ := cmd.Flags().GetString("ref")
130-
base, _ := cmd.Flags().GetString("base")
131129
format, _ := cmd.Flags().GetString("format")
132130
useColor, _ := cmd.Flags().GetBool("color")
133131
width, _ := cmd.Flags().GetInt("width")
@@ -142,13 +140,6 @@ Examples:
142140
ref = "HEAD"
143141
}
144142

145-
// Build the git ref spec
146-
gitRef := ref
147-
if base != "" {
148-
// Two-revision comparison: base..ref
149-
gitRef = base + ".." + ref
150-
}
151-
152143
// Create executor and connect
153144
exec, logger := newLoggedExecutor("subcommand")
154145
defer logger.Close()
@@ -169,7 +160,7 @@ Examples:
169160
Width: width,
170161
}
171162

172-
if err := exec.DiffLocal(gitRef, opts); err != nil {
163+
if err := exec.DiffLocal(ref, opts); err != nil {
173164
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
174165
os.Exit(1)
175166
}

cmd/mxcli/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ func init() {
228228
diffCmd.Flags().IntP("width", "w", 120, "Terminal width for side-by-side format")
229229

230230
// Diff-local command flags
231-
diffLocalCmd.Flags().StringP("ref", "r", "HEAD", "Git reference to compare against (target revision)")
232-
diffLocalCmd.Flags().StringP("base", "b", "", "Base revision for two-revision diff (e.g., --base main --ref feature)")
231+
diffLocalCmd.Flags().StringP("ref", "r", "HEAD", "Git ref or range (e.g., HEAD, main, main..feature)")
233232
diffLocalCmd.Flags().StringP("format", "f", "unified", "Output format: unified, side, struct")
234233
diffLocalCmd.Flags().BoolP("color", "", false, "Use colored output")
235234
diffLocalCmd.Flags().IntP("width", "w", 120, "Terminal width for side-by-side format")

docs-site/src/appendixes/quick-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ Cross-reference commands require `REFRESH CATALOG FULL` to populate reference da
541541
| Test | `mxcli test tests/ -p app.mpr` | `.test.mdl` / `.test.md` files |
542542
| Diff script | `mxcli diff -p app.mpr changes.mdl` | Compare script vs project |
543543
| Diff local | `mxcli diff-local -p app.mpr --ref HEAD` | Git diff for MPR v2 |
544-
| Diff revisions | `mxcli diff-local -p app.mpr --base main --ref feature` | Compare two git revisions |
544+
| Diff revisions | `mxcli diff-local -p app.mpr --ref main..feature` | Compare two git revisions |
545545
| OQL | `mxcli oql -p app.mpr "SELECT ..."` | Query running Mendix runtime |
546546
| External SQL | `mxcli sql --driver postgres --dsn '...' "SELECT 1"` | Direct database query |
547547
| Docker build | `mxcli docker build -p app.mpr` | Build with PAD patching |

docs-site/src/tools/diff.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ mxcli diff-local -p app.mpr --ref HEAD~1
3535
# Compare against a branch
3636
mxcli diff-local -p app.mpr --ref main
3737

38-
# Compare two arbitrary revisions
39-
mxcli diff-local -p app.mpr --base main --ref feature-branch
38+
# Compare two arbitrary revisions (git range syntax)
39+
mxcli diff-local -p app.mpr --ref main..feature-branch
4040

41-
# Compare two specific commits
42-
mxcli diff-local -p app.mpr --base abc1234 --ref def5678
41+
# Three-dot range (changes since common ancestor)
42+
mxcli diff-local -p app.mpr --ref main...feature-branch
4343
```
4444

4545
### MPR v2 Requirement
@@ -75,8 +75,8 @@ mxcli diff-local -p app.mpr --ref HEAD~2
7575

7676
```bash
7777
# What changed between main and your feature branch
78-
mxcli diff-local -p app.mpr --base main --ref feature-branch
78+
mxcli diff-local -p app.mpr --ref main..feature-branch
7979

8080
# Feed diff into an LLM for review
81-
mxcli diff-local -p app.mpr --base main --ref feature-branch > changes.diff
81+
mxcli diff-local -p app.mpr --ref main..feature-branch > changes.diff
8282
```

0 commit comments

Comments
 (0)