Skip to content

task: Add root flag for breaking check command#221

Merged
hound672 merged 10 commits into
mainfrom
task/219-root-braking-check
May 5, 2026
Merged

task: Add root flag for breaking check command#221
hound672 merged 10 commits into
mainfrom
task/219-root-braking-check

Conversation

@hound672
Copy link
Copy Markdown
Contributor

@hound672 hound672 commented May 3, 2026

To resolve: #219

Yakwilik
Yakwilik previously approved these changes May 3, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds --root support to easyp breaking so proto import resolution can work when proto sources live under a directory that should not be part of the proto package/import path (matching the existing easyp lint --root/--path behavior).

Changes:

  • Introduces --root flag for the breaking command and wires it through CLI root resolution.
  • Extends breaking check core logic and git tree walking to apply a “root prefix” when opening imported proto files from a git ref.
  • Updates the git walker interface and go-git adapter to accept both root and path.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
internal/api/breaking_check.go Adds --root flag and passes resolved roots into core breaking check.
internal/core/breaking_check.go Computes git-relative paths for comparing against a ref; passes root/path into git walker.
internal/core/dom.go Extends CurrentProjectGitWalker interface to accept root.
internal/adapters/go_git/get_dir_walker.go Plumbs root into NewGitTreeWalker.
internal/fs/go_git/dir_walker.go Extends git tree walker to carry a root-aware adapter.
internal/fs/go_git/adapter.go Implements root-aware import file opening for git tree reads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +38
flagBreakingCheckRoot = &cli.StringFlag{
Name: "root",
Usage: "set root directory for file search (default: current working directory)",
Required: false,
HasBeenSet: false,
Value: "",
Aliases: []string{"r"},
Comment thread internal/core/breaking_check.go Outdated
rel, err := filepath.Rel(projectRoot, workingDir)
if err != nil {
return nil, fmt.Errorf("filepath.Rel: %w", err)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot --root флаг для команды breaking_check может быть глобальным, так же как и в других командах, то есть может быть абсолютным путем до директории

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --root flag already accepts absolute paths via resolveRoots (same as lint/generate). The changes in commit 58dbf67 properly handle this:

  • Added filepath.IsLocal(rel) validation: absolute paths inside the project root work fine (e.g. --root=/project/proto with project root at /projectrel="proto"). Absolute paths outside the project root now return a clear error (root path "/other/path" is outside project root "/project") instead of silently producing invalid .. git tree paths.
  • Git tree paths are now built with path.Join on forward-slash-converted inputs, ensuring correct cross-platform behavior.
  • The CurrentProjectGitWalker mock has been updated to match the new 4-parameter GetDirWalker interface.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot разве это правильно? в командах generate/lint же таких ограничений нет.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit 8148ffe removes the restriction. GetDirWalker now uses PlainOpenWithOptions(DetectDotGit: true) to find the git repo by searching upward from --root, then computes the git-tree path relative to the actual worktree root. This means --root can be any absolute or relative path inside the git repository — including directories outside the config file's directory — consistent with generate/lint behaviour.

Comment thread internal/core/breaking_check.go Outdated
Comment on lines 29 to 51
gitPath := filepath.Join(rel, path)
c.logger.Debug(
ctx, "Paths for breaking check",
slog.String("rel", rel),
slog.String("path", path),
slog.String("gitPath", gitPath),
)

if err := c.Download(ctx); err != nil {
return nil, fmt.Errorf("c.Download: %w", err)
}

// read current state
fsWalker := fs.NewFSWalker(workingDir, path)
currentProtoFiles, err := c.readProtoFiles(ctx, fsWalker)
if err != nil {
return nil, fmt.Errorf("c.readCurrentProtoFiles: %w", err)
}

// read from ref branch
againstFSWalker, err := c.currentProjectGitWalker.GetDirWalker(
workingDir, c.breakingCheckConfig.AgainstGitRef, path,
projectRoot, c.breakingCheckConfig.AgainstGitRef, rel, gitPath,
)
Comment thread internal/core/dom.go
Comment on lines 26 to 29
// CurrentProjectGitWalker is provider for fs walking for current project
CurrentProjectGitWalker interface {
GetDirWalker(workingDir, gitRef, path string) (DirWalker, error)
GetDirWalker(workingDir, gitRef, root, path string) (DirWalker, error)
}
Comment thread internal/fs/go_git/adapter.go Outdated
Comment on lines +16 to +24
func (a *GitTreeDiskAdapter) Open(name string) (io.ReadCloser, error) {
gitFile, err := a.File(name)
if err == nil {
return gitFile.Reader()
}

// add root and try to open again
withRoot := path.Join(a.root, name)
gitFile, err = a.File(withRoot)
Comment thread internal/fs/go_git/adapter.go Outdated
Comment on lines +22 to +24
// add root and try to open again
withRoot := path.Join(a.root, name)
gitFile, err = a.File(withRoot)
Comment on lines 18 to 24
type GitTreeWalker struct {
*GitTreeDiskAdapter

tree *object.Tree
root string
path string
}
Copilot AI requested a review from Yakwilik May 3, 2026 20:35
Yakwilik
Yakwilik previously approved these changes May 3, 2026
@hound672 hound672 merged commit 9be34bb into main May 5, 2026
1 check passed
@hound672 hound672 deleted the task/219-root-braking-check branch May 5, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] No 'root' option in easyp breaking command

5 participants