dlang / dub

Package and build management system for D
MIT License
674 stars 228 forks source link

`fatal: '--detach' cannot be used with '-b/-B/--orphan'` #2697

Open CyberShadow opened 1 year ago

CyberShadow commented 1 year ago

dub.sdl:

name "test"

dependency "openssl" repository="git+https://github.com/CyberShadow/deimos-openssl" version="~107-openssl-+-stdconv-=-linker-error"

Prints fatal: '--detach' cannot be used with '-b/-B/--orphan' and exits.

WebFreak001 commented 1 year ago

your version is malformed, it must be a git commit hash if you are using repository on your dependency

CyberShadow commented 1 year ago
Geod24 commented 9 months ago

For me it even SEGV:

 % dub build
fatal: '--detach' cannot be used with '-b/-B/--orphan'
[2]    678860 segmentation fault  dub build

On master it at least prints which dependency creates the issue:

% ../bin/dub build
fatal: '--detach' cannot be used with '-b/-B/--orphan'
Error Unable to fetch 'openssl@git+https://github.com/CyberShadow/deimos-openssl' using git - does the repository and version exists?

But yes, we need to make this work.

katyukha commented 2 months ago

Hi all,

I got same issue. This is not related to version, but it is related to git itself (the command dub sends to git).

Dub's single file to reproduce:

#!/usr/bin/env dub
/+ dub.sdl:
    name "test_bad_git_clone"
    dependency "theprocess" repository="git+https://github.com/katyukha/TheProcess.git" version="~dev"
+/
void main(string[] argv) {
    import std.stdio;
    writeln("Hello world");
}

Dub runs command like git checkout --detach branch, that fails in case when branch is not local. It is better to split this command on two:

git checkout branch  # just checkout branch
git checkout --detach  # detach (do not track branch)

Simple cases to reproduce this issue:

root@752049377c83:/tmp# git clone --no-checkout https://github.com/katyukha/TheProcess
root@752049377c83:/tmp# cd TheProcess/
root@752049377c83:/tmp/TheProcess# git status

will result in

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    deleted:    .github/workflows/tests.yml
    deleted:    .gitignore
    deleted:    CHANGELOG.md
    deleted:    LICENSE
    deleted:    README.md
    deleted:    dub.sdl
    deleted:    dub.selections.json
    deleted:    source/theprocess/exception.d
    deleted:    source/theprocess/package.d
    deleted:    source/theprocess/process.d
    deleted:    source/theprocess/utils.d

So, now let's try to checkout to dev and detach in dub way:

root@752049377c83:/tmp/TheProcess# git checkout --detach dev
fatal: '--detach' cannot be used with '-b/-B/--orphan'

As we see, we got same error.

Now, let's try to split commands:

root@752049377c83:/tmp/TheProcess# git checkout dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
Switched to a new branch 'dev'
root@752049377c83:/tmp/TheProcess# git checkout --detach
HEAD is now at c29746c [FIX] make bahavior of ensureStatus consistent in case of command output on error
root@752049377c83:/tmp/TheProcess# git status
HEAD detached at c29746c
nothing to commit, working tree clean

As we see, this way it works.

Also, it is interesting to note, that if we checkout and detach in dub way on default branch, it also works:

root@752049377c83:/tmp/TheProcess# cd ..
root@752049377c83:/tmp# rm -r TheProcess/
root@752049377c83:/tmp# git clone --no-checkout https://github.com/katyukha/TheProcess
Cloning into 'TheProcess'...
remote: Enumerating objects: 107, done.
remote: Counting objects: 100% (107/107), done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 107 (delta 49), reused 90 (delta 33), pack-reused 0
Receiving objects: 100% (107/107), 25.10 KiB | 458.00 KiB/s, done.
Resolving deltas: 100% (49/49), done.
root@752049377c83:/tmp# cd TheProcess/
root@752049377c83:/tmp/TheProcess# git status               
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    deleted:    .github/workflows/tests.yml
    deleted:    .gitignore
    deleted:    CHANGELOG.md
    deleted:    LICENSE
    deleted:    README.md
    deleted:    dub.sdl
    deleted:    dub.selections.json
    deleted:    source/theprocess/exception.d
    deleted:    source/theprocess/package.d
    deleted:    source/theprocess/process.d
    deleted:    source/theprocess/utils.d

root@752049377c83:/tmp/TheProcess# git checkout --detach master
HEAD is now at da72560 [FIX] Better handling of environment variables in `execv` method.
Your branch is up to date with 'origin/master'.
root@752049377c83:/tmp/TheProcess# git status
HEAD detached at refs/heads/master
nothing to commit, working tree clean

So, for default (main/master) branches dub way of checkout worked by accident.

The code that caused this error: https://github.com/dlang/dub/blob/v1.38.1/source/dub/internal/git.d#L160

I hope, this will be fixed soon.

Thank you)