Skip to content

Running Flutter CLI in Git Hooks within a Submodule Corrupts Dart SDK #165390

Closed

Description

@Xm798

Executing Flutter CLI commands within Git hooks inside a submodule repository can result in the Dart SDK being corrupted. This issue makes all Flutter/Dart commands unusable, requiring a full reinstallation of the Flutter SDK to recover.

Steps to Reproduce

  1. Clone a minimal reproduction repository that contains a submodule where the Flutter project resides:

    git clone [email protected]:Xm798/example-project --recurse-submodules
  2. Create a Git pre-commit hook inside the submodule at .git/modules/submodules/example-submodule/hooks/pre-commit and add any Flutter-related commands, such as:

    flutter doctor
    dart format .
  3. In the submodule directory (submodules/example-submodule), commit any change to trigger the hook:

    git commit -m "Trigger pre-commit hook"
  4. Observe the following error:

    Downloading Darwin arm64 Dart SDK from Flutter engine 780e976079f7c9e9cc1f106566bc155e4fbf0297...
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   258  100   258    0     0    692      0 --:--:-- --:--:-- --:--:--   693
    [/Users/Cyrus/opt/flutter/bin/cache/dart-sdk-darwin-arm64.zip]
      End-of-central-directory signature not found.  Either this file is not
      a zipfile, or it constitutes one disk of a multi-part archive.  In the
      latter case the central directory and zipfile comment will be found on
      the last disk(s) of this archive.
    unzip:  cannot find zipfile directory in one of /Users/Cyrus/opt/flutter/bin/cache/dart-sdk-darwin-arm64.zip or
            /Users/Cyrus/opt/flutter/bin/cache/dart-sdk-darwin-arm64.zip.zip, and cannot find /Users/Cyrus/opt/flutter/bin/cache/dart-sdk-darwin-arm64.zip.ZIP, period.
    
    It appears that the downloaded file is corrupt; please try again.
    If this problem persists, please report the problem at:
      https://github.com/flutter/flutter/issues/new?template=1_activation.yml
    
  5. After this failure, running any Flutter or Dart commands results in:

    $flutter --version
    /Users/Cyrus/opt/flutter/bin/internal/shared.sh: line 268: /Users/Cyrus/opt/flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
  6. Checking the Flutter cache directory reveals that the Dart SDK has been entirely removed:

    ls -lah /Users/Cyrus/opt/flutter/bin/cache/dart-sdk/
    drwxr-xr-x@  2 Cyrus  staff    64B  3 18 20:18 .
    drwxr-xr-x@ 31 Cyrus  staff   992B  3 18 20:18 ..

Actual results

The issue originates from the script bin/internal/update_engine_version.sh, which attempts to determine the Flutter branch and engine version using:

BRANCH=$(git -C "$FLUTTER_ROOT" rev-parse --abbrev-ref HEAD)
ENGINE_VERSION=$(git -C "$FLUTTER_ROOT" merge-base HEAD origin/master)

However, when running inside a Git hook in a submodule, git sets the environment variable GIT_DIR to the submodule’s repository. This causes -C "$FLUTTER_ROOT" to be ignored, leading to incorrect values being retrieved. For example, in the error log above, the commit hash 780e976079f7c9e9cc1f106566bc155e4fbf0297 actually belongs to the latest commit in the submodule:

commit 780e976079f7c9e9cc1f106566bc155e4fbf0297 (HEAD -> master, origin/master, origin/HEAD)
Author: Xm798 <[email protected]>
Date:   Tue Mar 18 19:57:44 2025 +0800

Additionally, bin/internal/update_dart_sdk.sh deletes the old Dart SDK before successfully downloading a new one, leading to a completely broken development environment if the download fails.

This issue forces users to completely reinstall Flutter SDK to restore functionality, significantly disrupting development workflows.

Logs

No response

Flutter Doctor output

Doctor output
/Users/Cyrus/opt/flutter/bin/internal/shared.sh: line268: /Users/Cyrus/opt/flutter/bin/cache/dart-sdk/bin/dart: No such file or directory

Activity

  1. darshankawar commented on Mar 19, 2025

    @darshankawar
    Member

    @Xm798
    Please check if this issue resembles your case or not.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 19, 2025
  3. Xm798 commented on Mar 19, 2025

    @Xm798
    Author

    @darshankawar
    Thank you for your response. I have reviewed the issue you mentioned, but it does not seem related to my case. This issue is specifically caused by the behavior of bin/internal/update_engine_version.sh when executed inside a Git submodule, and not related to Xcode but rather to how Flutter’s update scripts interact with Git in a submodule environment.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 19, 2025
  5. hyiso commented on Mar 19, 2025

    @hyiso
    Contributor

    @Xm798
    You can check whether #140688 (comment) can help

  6. Xm798 commented on Mar 19, 2025

    @Xm798
    Author

    Yeah, that comment does help as a temporary workaround. But there’s one thing to keep in mind—issue #140688 was just about failing to get the Flutter version, while the latest script actually breaks the Dart SDK, making all Flutter CLI commands unusable. This is a much bigger hassle for developers since it forces a full Flutter SDK reinstall.

    I really think Flutter needs a more reliable way to check the version and update the Dart SDK, so that even if something goes wrong, it doesn’t completely mess up the dev environment.
    @hyiso

  7. darshankawar commented on Mar 20, 2025

    @darshankawar
    Member

    Keeping the issue open for team's tracking.

  8. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Mar 20, 2025
  9. added
    P1High-priority issues at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Mar 24, 2025
  10. 5 remaining items

  11. added a commit that references this issue on Mar 24, 2025
    f2e1534
  12. added a commit that references this issue on Mar 24, 2025
    7255b9b
  13. jtmcdole commented on Mar 24, 2025

    @jtmcdole
    Member

    Also, unfortunately, my dart-sdk.old folder is empty too, so my only option was to download the full Flutter SDK again.

    You could also just delete the "bin/cache" folder - the scripts (ps1 & sh) will download the contents again.

  14. added a commit that references this issue on Mar 24, 2025
    2250d39
  15. added a commit that references this issue on Mar 24, 2025
    a9503d6
  16. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 25, 2025
  17. added a commit that references this issue on Apr 4, 2025
    b694378
  18. github-actions commented on Apr 8, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Apr 8, 2025
  20. jtmcdole commented on Apr 14, 2025

    @jtmcdole
    Member

    Landed in stable 3.29.3

  21. added a commit that references this issue on Jun 9, 2025
    b67bd94
  22. added a commit that references this issue on Aug 14, 2025
    52c70d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

r: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions