Skip to main content

Scenario: init-then-cloned

Known bug, #11. This page shows what git-splice does today, bug included. See all known bugs.

A splice made by init was published, and a colleague clones the monorepo. Until the clone fetches, status, log and diff treat the upstream as empty, though it has commits. This is a known bug, #11.

  • Monorepo (lib/a/): a fresh clone of a monorepo in which lib/a/ was made a splice with init and pushed twice.
  • Upstream ($UPSTREAM, reached as https://git.example.com/a.git): the two pushed commits, splice: init lib/a and second version.

A splice made by init records no synced commit, and push doesn't write one. A fresh clone has no fetched refs either, so it can't tell this splice from one whose upstream is still empty. A splice made by clone records its synced commit, and a fresh clone says it was never fetched.

Workaround: git splice fetch (or pull, which fetches) in the clone. Nothing is lost meanwhile: the rebuild produces the commits the upstream already has, so a push without a fetch adds to them, or changes nothing. A push before the fetch shows that, though its message is wrong too.

Output​

setup.bash builds this state:

$ build_scenario scenario_init_then_cloned https://git.example.com/a.git

.splice has no synced commit:

$ cat lib/a/.splice
[splice]
id = a11f5cf4ef8965e5
[upstream "origin"]
url = https://git.example.com/a.git

status takes the splice for new, as if the upstream had no such branch, though it has:

$ git splice status
On branch main

new, ahead 2 lib/a push creates the branch
$ git -C "$UPSTREAM" log --format=%s main
second version
splice: init lib/a

log shows both published commits as unpushed:

$ git splice log
=== lib/a (upstream has no 'main' branch)
< f9832ad second version (Test <test@example.com>)
< f0fcdd0 splice: init lib/a (Test <test@example.com>)

merge doesn't: it never fetches, so it can't tell an empty upstream from one it hasn't fetched, and says so, even after a failed first fetch:

$ git splice merge lib/a
?? lib/a: not fetched yet -- run 'git splice fetch lib/a' first
!! Failed: lib/a
[1]

diff shows the whole folder as a change to push:

$ git splice diff
=== lib/a
diff --git a/file.txt b/file.txt
new file mode 100644
index 0000000..57be07d
--- /dev/null
+++ b/file.txt
@@ -0,0 +1,2 @@
+first version
+second version

After a fetch, the clone sees the upstream as it is:

$ git splice fetch
ok lib/a fetched
$ git splice status
On branch main

up to date lib/a