threads / discuss / 31863

git subtree error (just how do you expect me to merge 0 trees?)

Subject: git subtree error (just how do you expect me to merge 0 trees?)

## tl;dr

7 messages between Oct 18, 2012 and Jan 1, 2013.

replies: 6people: 3as markdown or json

Drew Crawford· Oct 18, 2012, 23:04 UTC · lore
I noticed today that if you leave off the branch name from git subtree like so:

$ git subtree add --prefix somewhere -m "adding CDH as subtree" path/to/repo warning: read-tree: emptying the index with no arguments is deprecated; use --empty fatal: just how do you expect me to merge 0 trees?

The error message is not particularly helpful (and seems to actually be in read-subtree?)  The solution in my case was to add the branch name on the end of the command.
Ideally it would be better to emit an error-message from a script higher up the calling chain that would be more descriptive about the problem (such as suggesting no branch is specified).
greened@obbligato.org· Jan 1, 2013, 01:44 UTC · re: Drew Crawford · lore

Re: git subtree error (just how do you expect me to merge 0 trees?)

Drew Crawford <drew@drewcrawfordapps.com> writes:
Show 9 quoted lines
> I noticed today that if you leave off the branch name from git subtree like so:
>
> $ git subtree add --prefix somewhere -m "adding CDH as subtree" path/to/repo
> warning: read-tree: emptying the index with no arguments is deprecated; use --empty
> fatal: just how do you expect me to merge 0 trees?
>
> The error message is not particularly helpful (and seems to actually be in read-subtree?)  The solution in my case was to add the branch name on the end of the command.
>
> Ideally it would be better to emit an error-message from a script higher up the calling chain that would be more descriptive about the problem (such as suggesting no branch is specified).--
Good idea.  I'll code it up.
                        -David
greened@obbligato.org· Jan 1, 2013, 02:09 UTC · re: Drew Crawford · lore

Re: git subtree error (just how do you expect me to merge 0 trees?)

Drew Crawford <drew@drewcrawfordapps.com> writes:
> Ideally it would be better to emit an error-message from a script
> higher up the calling chain that would be more descriptive about the
> problem (such as suggesting no branch is specified).--

I'm looking at implementing this but I need a bit of help from the git experts.

git-subtree add accepts either a refspec or a path to a repository and a refspec. With one positional option, git-subtree add simply assumes it's a refspec. Is there an easy way to check whether a string is a proper refspec? Even better would be a way to check if a string is a path to a git repository.

                         -David
Junio C Hamano· Jan 1, 2013, 03:16 UTC · re: greened@obbligato.org · lore

Re: git subtree error (just how do you expect me to merge 0 trees?)

greened@obbligato.org writes:
> git-subtree add accepts either a refspec or a path to a repository and a
> refspec.
> With one positional option, git-subtree add simply assumes
> it's a refspec.  Is there an easy way to check whether a string is a
> proper refspec?  Even better would be a way to check if a string is a
> path to a git repository.

Do you literally mean "a path to a repository" in the above, or do you mean "a remote that is like what is accepted by 'git fetch'"? If you literary mean it is is a path to a git repository, you could obviously use "cd $there && git rev-parse --git-dir" or something.

On the other hand, if you mean the command takes a remote and an optional list of refspecs just like "git fetch" does, then I am not sure it is a good design in the first place to allow "refspecs only", if only to keep the interface similar to "git fetch" (you cannot omit remote and give refspecs, as you cannot interpret refspecs without knowing in the context of which remote they are to be interpreted).

I would imagine you could disambiguate and default to "origin" or something when you guessed that remote was omitted if you really wanted to, with a syntacitical heuristics, such as "a refspec will never have two colons in it", "a URL tends to begin with a short alphabet word, a colon and double-slash", etc.

greened@obbligato.org· Jan 1, 2013, 04:04 UTC · re: Junio C Hamano · lore

Re: git subtree error (just how do you expect me to merge 0 trees?)

Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
>> With one positional option, git-subtree add simply assumes
>> it's a refspec.  Is there an easy way to check whether a string is a
>> proper refspec?  Even better would be a way to check if a string is a
>> path to a git repository.
>
> Do you literally mean "a path to a repository" in the above, or do
> you mean "a remote that is like what is accepted by 'git fetch'"?

It's the latter as git-subtree calls git-fetch to do the work of getting revisions.

Show 7 quoted lines
> On the other hand, if you mean the command takes a remote and an
> optional list of refspecs just like "git fetch" does, then I am not
> sure it is a good design in the first place to allow "refspecs
> only", if only to keep the interface similar to "git fetch" (you
> cannot omit remote and give refspecs, as you cannot interpret
> refspecs without knowing in the context of which remote they are to
> be interpreted).

If just a refspec is given, git-subtree does a rev-parse in the current directory and that seems to work fine. It's what I as a user would expect to happen.

Show 5 quoted lines
> I would imagine you could disambiguate and default to "origin" or
> something when you guessed that remote was omitted if you really
> wanted to, with a syntacitical heuristics, such as "a refspec will
> never have two colons in it", "a URL tends to begin with a short
> alphabet word, a colon and double-slash", etc.

Hmm...I haven't added code to verify the repository/remote argument if given. I suppose a rev-parse --verify would suffice?

                        -David
Junio C Hamano· Jan 1, 2013, 05:54 UTC · re: greened@obbligato.org · lore

Re: git subtree error (just how do you expect me to merge 0 trees?)

greened@obbligato.org writes:
Show 12 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>>> With one positional option, git-subtree add simply assumes
>>> it's a refspec.  Is there an easy way to check whether a string is a
>>> proper refspec?  Even better would be a way to check if a string is a
>>> path to a git repository.
>>
>> Do you literally mean "a path to a repository" in the above, or do
>> you mean "a remote that is like what is accepted by 'git fetch'"?
>
> It's the latter as git-subtree calls git-fetch to do the work of
> getting revisions.

If that is the case, t should behave similar to 'git fetch' for consistency. If you want to name "current repository", you can simply give "." as the repository parameter; this has long been supported by 'git fetch' (as 'git pull . $branch' has been the way to say 'git merge' for a long time).

greened@obbligato.org· Jan 1, 2013, 02:39 UTC · re: Drew Crawford · lore

Re: git subtree error (just how do you expect me to merge 0 trees?)

Drew Crawford <drew@drewcrawfordapps.com> writes:
> Ideally it would be better to emit an error-message from a script
> higher up the calling chain that would be more descriptive about the
> problem (such as suggesting no branch is specified).--

Ok, I used git rev-parse --verify and I have this working now. Will send to Junio in the batch with fixes from other folks.

Thanks for catching this!
                         -David

← back to recent threads