Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Initializing project with git fails #1228

Closed
cobyge opened this issue Jun 10, 2022 · 4 comments · Fixed by #1265 or #1284
Closed

🐛 BUG: Initializing project with git fails #1228

cobyge opened this issue Jun 10, 2022 · 4 comments · Fixed by #1265 or #1284
Assignees
Labels
bug Something that isn't working

Comments

@cobyge
Copy link

cobyge commented Jun 10, 2022

What version of Wrangler are you using?

2.0.9

What operating system are you using?

WSL Ubuntu 20.04.4

Describe the Bug

When I try to create a new project with git initialization, I get an error as show below.
Git version 2.25.1 (Latest for Ubuntu 20.04.4)

➜ wrangler init testproj
 ⛅️ wrangler 2.0.9
-------------------
Using npm as package manager.
✨ Created testproj/wrangler.toml
Would you like to use git to manage this Worker? (y/n)

✘ [ERROR] Command failed with exit code 128: git branch -m main

  error: refname refs/heads/master not found
  fatal: Branch rename failed


If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose

➜  ~ git --version
git version 2.25.1

➜  cd testproj
➜  git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        wrangler.toml

nothing added to commit but untracked files present (use "git add" to track)

@cobyge cobyge added the bug Something that isn't working label Jun 10, 2022
@petebacondarwin
Copy link
Contributor

Thanks for the issue report @cobyge - this is really strange since it is saying that it cannot find the master branch in order to rename it but then it is on the master branch... I'll try to reproduce it myself. Do you know if this happens on other OSes?

@petebacondarwin petebacondarwin moved this to Untriaged in workers-sdk Jun 10, 2022
@petebacondarwin petebacondarwin moved this from Untriaged to Selected for development in workers-sdk Jun 10, 2022
@petebacondarwin petebacondarwin self-assigned this Jun 10, 2022
@sunilhari
Copy link

I have read over the internet that git branch -m main works only when you have initial commit .( Although this is not the behaviour in my system). Ref : https://stackoverflow.com/questions/66673759/git-branch-m-main

I was wondering instead of moving/renaming the branch by default ( here we are also making assumption that branch is not named as main by default) why don't we tell to create branch main by default when initializing the repo

So instead of

 await execa("git", ["init"], {
    cwd: creationDirectory,
   });

why dont we use

 await execa("git", ["init" ,"-b","main"], {
    cwd: creationDirectory,
   });

and get rid of

 await execa("git", ["branch", "-m", "main"], {
            cwd: creationDirectory,
          });

@petebacondarwin
Copy link
Contributor

We recently moved away from init -b main because of a lack of support in older versions of git.
It seems this new approach is not flawless either.

From what I read, as long as we create an initial commit then we would be safe to rename the branch.
This actually seems like a sensible thing to do in any case - i.e. commit the first set up of code generated by wrangler init.

@sunilhari
Copy link

sunilhari commented Jun 13, 2022

Okay got it.So the idea would be to commit the initial files that get generated likewrangler.toml
Shall I sent a PR making above changes. a commit right after git init?

petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jun 15, 2022
… init`

Sometimes git is unable to rename a branch if it has no commits on it. So we now create an empty commit just before renaming.

Fixes cloudflare#1228
@petebacondarwin petebacondarwin moved this from Selected for development to In Review in workers-sdk Jun 15, 2022
@petebacondarwin petebacondarwin moved this from In Review to In Progress in workers-sdk Jun 15, 2022
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jun 15, 2022
… init`

Sometimes git is unable to rename a branch if it has no commits on it. So we now create an empty commit just before renaming.

Fixes cloudflare#1228
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jun 20, 2022
If `git` does not support the `--initial-branch` argument then just fallback to the default initial branch name.

We tried to be more clever about this but there are two many weird corner cases with different git versions on different architectures.
Now we do our best, with recent versions of git, to ensure that the branch is called `main` but otherwise just make sure we don't crash.

Fixes cloudflare#1228
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jun 20, 2022
If `git` does not support the `--initial-branch` argument then just fallback to the default initial branch name.

We tried to be more clever about this but there are two many weird corner cases with different git versions on different architectures.
Now we do our best, with recent versions of git, to ensure that the branch is called `main` but otherwise just make sure we don't crash.

Fixes cloudflare#1228
threepointone pushed a commit that referenced this issue Jun 20, 2022
If `git` does not support the `--initial-branch` argument then just fallback to the default initial branch name.

We tried to be more clever about this but there are two many weird corner cases with different git versions on different architectures.
Now we do our best, with recent versions of git, to ensure that the branch is called `main` but otherwise just make sure we don't crash.

Fixes #1228
Repository owner moved this from In Progress to Done in workers-sdk Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
3 participants