tsrc icon indicating copy to clipboard operation
tsrc copied to clipboard

Missing error message: when cloning a repository with main branch not being master

Open cgestes opened this issue 2 years ago • 7 comments

With debug activated:

=> Cloning missing repos
/home/cedric/src/jots $ git clone --origin origin [email protected]:jotshq/gotrue-dart.git --branch master --recurse-submodules gotrue-dart                                                      
Error: Failed to clone the following repos                                                                                                                                                    
* gotrue-dart : Cloning failed

the main branch of the repository is main not master. (this is the default in github now)

(btw I had the same issue with the manifest)

cgestes avatar Apr 07 '22 15:04 cgestes

maybe we could make it work, or provide an appropriate error message?

Also it would make sense to have a verbose output when it fails (or a hint that it exists), otherwise I need to re-run the command with verbose.

cgestes avatar Apr 07 '22 15:04 cgestes

@cgestes main branch is a GitHub specific branch name (not Git specific) therefore you shall indicate it as name branch like any dev branch.

Lecrapouille avatar Apr 12 '22 08:04 Lecrapouille

you are right Main is github specific. I think we can use the default cloning branch of git. (Git doesnt fail if no branch is specified) We probably can use the default branch of the repository instead of failing 😁

cgestes avatar Apr 12 '22 09:04 cgestes

Here's what I think is happening.

I assume your manifest looks like this:

repos:
  - dest: gotrue-dart
    url: [email protected]/jotshq/gotrue-dart

with no branch specified.

when we parse the manifest, we go through the following code

class Manifest:
   ...

   def _handle_repo(self, repo_config: Any) -> None:
       dest = repo_config["dest"]
       branch = repo_config.get("branch", "master")   # 'master' hard-coded there
       tag = repo_config.get("tag")
       ....

This explains why tsrc sync runs git clone with --branch master.

We could just modify the code to look like this:

   def _handle_repo(self, repo_config: Any) -> None:
-     branch = repo_config.get("branch", "master")   
+     branch = repo_config.get("branch")
       
class Repo:
    dest: str
-   branch: str
+   branch: Optional[str]

But then tsrc fails apart. tsrc sync (and other commands) need to know what the current branch of the repo is.

The only clean fix I can think of is to require the branch to be specified in the manifest, but this is a breaking change.

dmerejkowsky avatar Apr 23 '22 13:04 dmerejkowsky

Writing a failing test for this was a bit harder than I expected, but you can see it at the corresponding branch

dmerejkowsky avatar Apr 23 '22 13:04 dmerejkowsky

Can we get a proper error message when the branch does'nt exist?

Got this bug again, lost 10min again figuring out... even the verbose option doesn't show what is happening. There is really no easy way to understand what's happening.

Btw I think git is going to change the name of the default branch soon also.

cgestes avatar Sep 12 '22 17:09 cgestes

Can we get a proper error message when the branch does'nt exist?

Yup, we can. Turns out we introduced a generic run_git() method in the Task class but forgot to take advantage of it in the Cloner class ...

dmerejkowsky avatar Sep 22 '22 13:09 dmerejkowsky