tg.sh: ensure ensure_clean_tree works on unborn branches
commit689857cd7717ed182d39785b21d5f0fb631653a0
authorKyle J. McKay <mackyle@gmail.com>
Thu, 2 Sep 2021 00:37:31 +0000 (1 17:37 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Thu, 2 Sep 2021 00:37:31 +0000 (1 17:37 -0700)
treedb3fadce4ffc562f2724e13460d7453f6a1c1682
parent69d95be30b096fe1d72d591738b0a1d1d5c9fae8
tg.sh: ensure ensure_clean_tree works on unborn branches

The ensure_clean_tree function checks, among other things, to see
whether or not there are any changes sitting in the index that have
yet to be committed.

This can definitely still be the case (or not) for an unborn branch,
but it's not possible to detect it by diff'ing against 'HEAD' in
such a case since there is no valid HEAD yet.

Instead, when HEAD is not yet valid (i.e. it's an unborn branch),
diff against the empty tree.

Since Git v1.5.5 it's not even necessary for the empty tree to
actually be a real object in the repository for it to be used as a
diff target.

Update the setup_hashalgo_vars function to make "$mttree" available
as the appropriate empty tree hash to use for the current repository
and update ensure_clean_tree to use that whenever HEAD is not yet
valid.  This ensures that ensure_clean_tree gets the correct result
even when dealing with unborn branches.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
tg.sh