Repository: flutter
Issue: flutter naming project bug with git worktrees
Labels: c: new feature,tool,has reproducible steps,P3,found in release: 3.0,team-tool,triaged-tool

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. create a simple app called bug with `flutter create bug`
2. call `git init` to init a git repo, `git add .`, `git commit -m 'init'` and then connect this repo to any remote
3. now delete the repo from your machine and clone it as a worktree with the command `git clone --bare my_remote_url`
4. now you will have a bare repo of your project on your machine, let's pull our `main` branch (it could also be `master` depending on your git config)  by using `git worktree add main`
5. so now your code of your main branch exists at `bug.git/main` folder. now everything works just fine and your bundle id is something like `com.example.bug`
6. now we're assuming some new stuff came to flutter and we want to reinit `android` folder for example. we can just remove the `android` folder `rm -r android` and then call `flutter create .`


**Expected results:** <!-- what did you want to see? -->
what flutter should do is to get the name from `pubspec.yaml` because the name of the folder in this case presents the branch name and not the project name .

**Actual results:** <!-- what did you see? -->
although my project name in `pubspec.yaml` is still `bug`, flutter will take it from the folder name which currently is `main` as we're in the `main` branch of the worktree (`bug.git/main`).

<details>
  <summary>Logs</summary>

```

[✓] Flutter (Channel stable, 3.0.0, on macOS 12.3.1 21E258 darwin-arm, locale en-TR)
    • Flutter version 3.0.0 at /Users/adnanfahed/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee4e09cce0 (3 days ago), 2022-05-09 16:45:18 -0700
    • Engine revision d1b9a6938a
    • Dart version 2.17.0
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2)
    • Android SDK at /Users/adnanfahed/Library/Android/sdk
    • Platform android-31, build-tools 33.0.0-rc2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.67.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (3 available)
    • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64  • Android 11 (API 30) (emulator)
    • macOS (desktop)           • macos         • darwin-arm64   • macOS 12.3.1 21E258 darwin-arm
    • Chrome (web)              • chrome        • web-javascript • Google Chrome 101.0.4951.64
    ! Error: Adnan’s iPhone X is not connected. Xcode will continue when Adnan’s iPhone X is connected. (code -13)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

```

</details>


here is an example of the changes after `flutter create .`:
<img width="578" alt="Screen Shot 2022-05-13 at 11 53 12" src="https://user-images.githubusercontent.com/54329101/168248475-69226a16-e3b6-4d33-9a81-c2a028ef74a4.png">