Skip to main content

Scenario: init-then-cloned

A splice made by init was published, and a colleague clones the monorepo. Until the clone fetches, status, merge, 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: 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

.splice has no synced commit:

$ git config --file lib/a/.splice --list
splice.id=[0-9a-f]{16} (regex)
upstream.origin.url=$UPSTREAM

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 finds nothing to merge:

$ git splice merge lib/a
ok lib/a: upstream has no 'main' branch -- nothing to merge

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