Use case 1: Bootsrapping a remote repository

Having to bootstrap a remote empty repository is a quite common use case, a sysadmin on our repository hosting will provide us with an ssh or any other supported protocol account and a url to access to our public repository. However in the first place, the repository will be empty, so we have to populate it with some content.

Bazaar

We will use a local repository for convenience:

~$ bzr init source

Now, we try to clone the repository from the "remote" location and perform the first commit:

~$ bzr clone source local_branch
Branched 0 revision(s).
~$ cd local_branch/
~/local_branch$ touch a
~/local_branch$ bzr add a
added a
~/local_branch$ bzr commit -m "Added a"
Committing to: /home/aruiz/local_branch/
added a
Committed revision 1.

Finally, we push back the content to the source repository.

~/local_branch$ bzr push
bzr: ERROR: No push location known or specified.

Oops, it didn't stored the origin, let's try again:

~/local_branch$ bzr push ../source
All changes applied successfully.
Pushed up to revision 1.

Conclusion

The only usability glitch in this test for bazaar is the fact that it didn't stored the original branch as the default one for the push operation, however the origin will be remembered afer the first push so not a big deal, everything else works as expected.

Git

We will use a local repository for convenience:

~$ git init source
usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]

Ouch! Seems we have to create the directory and enter into it first:

~$ mkdir source
~$ cd source
~/source$ git init
Initialized empty Git repository in .git/

Now, we try to clone the repository from the "remote" location and perform the first commit:

~$ git clone source local_branch
Initialized empty Git repository in /home/aruiz/local_branch/.git/
fatal: cannot clone empty repository

So, an empty repository cannot be cloned... okay... what should I do? Maybe create it myself? Let's try...

~$ mkdir local_branch
~$ cd local_branch/
~/local_branch$ git init
Initialized empty Git repository in .git/
~/local_branch$ touch a
~/local_branch$ git add a 
~/local_branch$ git commit -m "Added a"
Created initial commit dee436e: Added a
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a

Finally, we push back the content to the source repository.

~/local_branch$ git push ../source/
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '../source/'

Okay, what's wrong here... what's a ref? and why should I specify a branch? The push target repository is empty and the one with the commit has no branches.

Anyway, let's try to figure out how to specify a branch on a pull operation:

~$ git help push
...

No explicit documentation on how to specify a branch in the usage explanation, and looking for "branch" in the man page is not any helpful either. However, the first of the examples seems to give us an advice about pushing the master branch to the origin:

~/local_branch$ git push ../source/ master
Counting objects: 3, done.
Unpacking objects: 100% (3/3), done.
Writing objects: 100% (3/3), 198 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ../source/
 * [new branch]      master -> master

Conclusion

A few problems found during this use case.

  • Git doesn't support init on no directories other than the current working one
  • Git doesn't clone empty repositories. This seems stupid on a first place, but in this particular use case, is something logical to do. The user expects to take what he has on the server, commit, and push back.
  • Message about Git initializing an empty directory right before the error could be misleading if no attention is paid, the user don't need that information at all unless the operation succeed.
  • If no other branches are in place and the origin is empty, the push operation should not require the branch argument.
  • "No refs in common and none specified; doing nothing." is not any helpful for this particular error.
  • Man page examples were helpful, but no references on how to specify the branch on the usage explanation on top of the document, there's some sort of lack of consistency between this particular error message and the manpage.

Mercurial

We will use a local repository for convenience:

~$ hg init source

Now, we try to clone the repository from the "remote" location and perform the first commit:

~$ hg clone source local_branch
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
~$ cd local_branch/
~/local_branch$ touch a
~/local_branch$ hg add a
~/local_branch$ hg commit -m "Added a"
No username found, using 'user@localhost.localdomain' instead

Mmm... I wonder how to fix that.. anyway

Finally, we push back the content to the source repository.

~/local_branch$ hg push
pushing to /home/aruiz/source
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files

Conclusion

Every operation went as expected. However, the "No username found..." message could provide pointers on how to setup the username/email properly to avoid that error on the future. The other DVCS tools didn't notice the absence of a valid username.

AlbertoRuiz/DVCSUsability/BootStrappingEmptyRepo (last edited 2008-07-01 16:02:07 by rvburke)