melos icon indicating copy to clipboard operation
melos copied to clipboard

fix: `melos exec --diff=HEAD` does not detect uncommitted changes

Open motucraft opened this issue 5 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Version

6.1.0

Description

When using the melos exec --diff=HEAD command, I expected it to detect uncommitted changes and run the command in the affected packages. However, even though there are uncommitted changes, Melos detects 0 packages and does not execute the command.

To demonstrate this issue, I have prepared a sample project that can be found here:
melos_git_diff_issue

Steps to reproduce

  1. Clone the project from melos_git_diff_issue.
  2. Make some changes to a file in one of the packages (without committing).
  3. Run git diff HEAD to confirm that there are uncommitted changes.
  4. Execute the following command (Mac): melos exec --diff=HEAD -- basename $(pwd)
  5. Observe that Melos detects 0 packages, even though changes exist.

Expected behavior

According to the official documentation, the --diff filter should "filter packages based on whether there were changes between a commit and the current HEAD or within a range of commits."

I expected Melos to detect uncommitted changes between the last commit (HEAD) and the working directory, and then execute the specified command in those affected packages. Specifically, any package with changes between the latest commit and the current working directory should be included, and the command should run in those packages.

packageFilters is expected to behave similarly, allowing packages to be filtered based on changes between commits or the working directory.

Screenshots

Here are the relevant logs from running melos analyze and melos exec --diff=HEAD:

melos analyze
% melos analyze                            
$ melos analyze
  â””> /Users/motoki.osaki/github/motucraft/melos_git_diff_issue/.fvm/flutter_sdk/bin/dart analyze 
     â””> RUNNING (in 4 packages)

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
bar:
Analyzing bar...
No issues found!
bar: SUCCESS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
baz:
Analyzing baz...
No issues found!
baz: SUCCESS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
foo:
Analyzing foo...
No issues found!
foo: SUCCESS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
sample_app:
Analyzing sample_app...
No issues found!
sample_app: SUCCESS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$ melos analyze
  â””> /Users/motoki.osaki/github/motucraft/melos_git_diff_issue/.fvm/flutter_sdk/bin/dart analyze 
     â””> SUCCESS
  • git diff
% git diff HEAD                            
diff --git a/packages/baz/lib/baz.dart b/packages/baz/lib/baz.dart
index ec73657..01bf9f8 100644
--- a/packages/baz/lib/baz.dart
+++ b/packages/baz/lib/baz.dart
@@ -7,6 +7,6 @@ class Baz extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-    return const Text('Baz', style: TextStyle(fontSize: 24));
+    return const Text('baz', style: TextStyle(fontSize: 24));
   }
 }
  • melos exec
% melos exec --diff=HEAD -- basename $(pwd)
$ melos exec
  â””> basename /Users/motoki.osaki/github/motucraft/melos_git_diff_issue
     â””> RUNNING (in 0 packages)

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$ melos exec
  â””> basename /Users/motoki.osaki/github/motucraft/melos_git_diff_issue
     â””> SUCCESS

Additional context and comments

No response

motucraft avatar Sep 21 '24 15:09 motucraft