Have init --remote without a path default to ~/.bup as the other
--remote arguments (e.g. save) do. Previously (e.g. in 0.33.x) this
would just crash. Improve the related documentation and augment
test/ext/bup-init.
Thanks to Greg Troxel for suggesting improvements to the
documentation.
Signed-off-by: Rob Browning <
r...@defaultvalue.org>
Tested-by: Rob Browning <
r...@defaultvalue.org>
---
Documentation/
bup-init.1.md | 14 +++---
Documentation/
bup.1.md | 6 +--
lib/bup/client.py | 14 +++---
note/main.md | 11 +++++
test/ext/test-init | 92 ++++++++++++++++++++++++++++++-------
5 files changed, 103 insertions(+), 34 deletions(-)
diff --git a/Documentation/
bup-init.1.md b/Documentation/
bup-init.1.md
index 2c33631e..25563c6e 100644
--- a/Documentation/
bup-init.1.md
+++ b/Documentation/
bup-init.1.md
@@ -13,18 +13,16 @@ bup init [-r *host*:*path*] [*directory*]
# DESCRIPTION
`bup init` initializes a repository. The location will be the
-`*directory*` if provided, the directory specifed by any global `-d`
-argument (see `bup`(1)), the value of `BUP_DIR` in the environment if
-set, or `~/.bup`.
+`*directory*` or `--remote` if provided, the directory specifed by any
+global `-d` argument (see `bup`(1)), the value of `BUP_DIR` in the
+environment if set, or `~/.bup`.
# OPTIONS
-r, \--remote=[*user*@]*host*:[*path*], \--remote=URL
-: Initialize not only the local repository, but also the specified
- remote repository. This is not necessary if you intend to use the
- default location on the server (ie. with no *path*). By default
- the connection to the remote server is made with SSH. See bup(1)
- REMOTE OPTIONS for further information.
+: Initialize the specified *path* on the given *host*. Incompatible
+ with *directory*. See bup(1) REMOTE OPTIONS
+ for further information.
# EXAMPLES
bup init ~/archive
diff --git a/Documentation/
bup.1.md b/Documentation/
bup.1.md
index a6e22d4d..6bdc33f1 100644
--- a/Documentation/
bup.1.md
+++ b/Documentation/
bup.1.md
@@ -162,9 +162,9 @@ remote path as either a URL (see `REPOSITORY URLS` below) or a
`[*user*@]*host*:[*path*]`.
For either format, when there is no path, the default path on the
-server will be used, and SSH settings for the connection can be
-provided by a custom host to your `~/.ssh/config` file
-(`ssh_config(5)`).
+server will be used (`BUP_DIR` if set in the remote environment or
+`~/.bup`), and SSH settings for the connection can be provided by a
+custom host in your `~/.ssh/config` file (`ssh_config(5)`).
The argument is treated as a URL if it begins with a syntactically
valid URL scheme prefix that contains an "authority" (meaning that it
diff --git a/lib/bup/client.py b/lib/bup/client.py
index 1f1ea3dc..562c3663 100644
--- a/lib/bup/client.py
+++ b/lib/bup/client.py
@@ -326,14 +326,16 @@ class Client:
ctx.enter_context(self._transport)
self.conn = self._transport.conn
self._available_commands = self._get_available_commands()
+ mangled_path = b''
if self.path:
mangled_path = re.sub(br'[\r\n]', b' ', self.path)
- if create:
- self._require_command(b'init-dir')
- self.conn.write(b'init-dir %s\n' % mangled_path)
- else:
- self._require_command(b'set-dir')
- self.conn.write(b'set-dir %s\n' % mangled_path)
+ if create:
+ self._require_command(b'init-dir')
+ self.conn.write(b'init-dir %s\n' % mangled_path)
+ self.check_ok()
+ elif self.path:
+ self._require_command(b'set-dir')
+ self.conn.write(b'set-dir %s\n' % mangled_path)
self.check_ok()
if url.scheme == b'bup-rev':
legacy_id = _legacy_cache_id_for_remote(url.host, True)
diff --git a/note/main.md b/note/main.md
index 54b8a692..1e20dc7c 100644
--- a/note/main.md
+++ b/note/main.md
@@ -18,6 +18,12 @@ May require attention
commits if the `DEST` was not itself a commit (the parent would be
whatever `DEST` initially pointed to).
+* `bup init -r` (`--remote`) now only initializes the remote
+ repository, not the local and remote repositories, so `bup init -r
+ host:remote` and `bup -d local init -r host:remote` will only
+ initialze the `remote` repository, not `~/.bup` and `./local`
+ respectively.
+
* Following POSIX `ls`, `bup ls -l` no longer dereferences symlinks,
for example for `bup ls -l save/latest` (`bup ls -l save/latest/`
still does).
@@ -268,6 +274,11 @@ Bugs
dates). Previously it would fail with a message like "error: cannot
access SAVE in SAVE".
+* `bup init -r host:` (without a path) now initializes the default
+ remote repository (remote `BUP_DIR` or `~/.bup`). Previously it
+ would crash. This matches the behavior of `-r` for other commands
+ like `bup save -r`.
+
* When run on an existing repository, `bup init` will no longer change
existing `core.logAllRefUpdates` settings.
diff --git a/test/ext/test-init b/test/ext/test-init
index 51f61770..e0df05b9 100755
--- a/test/ext/test-init
+++ b/test/ext/test-init
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
. ./wvtest-bup.sh || exit $?
. ./dev/lib.sh || exit $?
+. ./test/lib/btl.sh
set -o pipefail
@@ -9,6 +10,15 @@ tmpdir="$(WVPASS wvmktempdir)" || exit $?
bup() { "$top/bup" "$@"; }
+validate_repo()
+{
+ local dir="$1"
+ WVPASS test -d "$dir"
+ WVPASS test -f "$dir/HEAD"
+ WVPASS test -f "$dir/config"
+ WVPASS test -d "$dir/objects/pack"
+}
+
WVPASS cd "$tmpdir"
@@ -17,46 +27,94 @@ WVPASS mkdir foo
WVEXPRC 2 bup -d nope save -t foo
WVPASS rmdir foo
+WVSTART 'only one positional argument allowed'
+WVFAIL err-to log bup init x y
+WVPASS test ! -e x
+WVPASS test ! -e y
+WVPASS grep 'only the directory positional argument is allowed' log
+
+WVSTART 'local and remote disallowed'
+WVFAIL err-to log bup init -r -:remote local
+WVPASS test ! -e remote
+WVPASS test ! -e local
+WVPASS grep 'cannot initialize both local and remote repo' log
+
+WVSTART 'initialization failure'
+WVEXPRC "$bup_exit_failure" err-to log bup init /dev/null
+WVPASS grep "could not init repository" log
+
WVSTART '-d repo argument'
WVPASS test ! -e repo
WVPASS bup -d repo init
-WVPASS test -d repo/refs/heads
-WVPASS test -d repo/objects/pack
+validate_repo repo
WVPASS rm -rf repo
WVSTART 'positional repo argument'
WVPASS test ! -e repo
WVPASS bup init repo
-WVPASS test -d repo/refs/heads
-WVPASS test -d repo/objects/pack
+validate_repo repo
WVPASS rm -rf repo
-WVSTART 'positional repo argument precdence over -d'
+WVSTART 'positional repo argument precedence over -d'
WVPASS test ! -e repod
WVPASS test ! -e repo
WVPASS bup -d repod init repo
WVPASS test ! -e repod
-WVPASS test -d repo/refs/heads
-WVPASS test -d repo/objects/pack
+validate_repo repo
WVPASS rm -rf repo
-WVSTART 'positional repo argument precdence over BUP_DIR'
+WVSTART 'positional repo argument precedence over BUP_DIR'
WVPASS test ! -e repod
WVPASS test ! -e repo
-export BUP_DIR=repod
-WVPASS bup init repo
-unset BUP_DIR
-WVPASS test ! -e repod
-WVPASS test -d repo/refs/heads
-WVPASS test -d repo/objects/pack
+(export BUP_DIR=repod
+ WVPASS bup init repo
+ WVPASS test ! -e repod
+ validate_repo repo)
WVPASS rm -rf repo
-WVSTART '--remote'
+WVSTART '--remote repo argument precedence over BUP_DIR'
+WVPASS rm -rf repo
+WVPASS test ! -e repo
+WVPASS test ! -e remote
+(export BUP_DIR=repo
+ WVPASS bup init --remote -:remote
+ validate_repo remote
+ WVPASS test ! -e repo)
WVPASS rm -rf repo
-WVPASS bup init --remote -:repo
-WVEXPRC "$bup_exit_failure" bup init /dev/null
+WVSTART 'no --remote path'
+WVPASS rm -rf home
+WVPASS mkdir home
+(unset BUP_DIR
+ export HOME="$(pwd)/home" # works because - isn't ssh
+ WVPASS bup init --remote -:
+ validate_repo home/.bup)
+WVPASS rm -rf home
+
+if test -z "$BUP_TEST_OTHER_BUP"; then
+ WVMSG 'Skipping --remote against other bup (no BUP_TEST_OTHER_BUP)'
+else
+ other_bup="$(printf "%q" "$BUP_TEST_OTHER_BUP")"
+ WVSTART "--remote -: against $other_bup"
+ WVPASS rm -rf home
+ WVPASS mkdir home
+ (unset BUP_DIR
+ export HOME="$(pwd)/home" # works because - isn't ssh
+ export BUP_TEST_SSH_BUP_PATH="$BUP_TEST_OTHER_BUP"
+ WVPASS bup init --remote -:
+ validate_repo home/.bup)
+ WVPASS rm -rf home
+ WVSTART "--remote -:path against $other_bup"
+ WVPASS rm -rf repo
+ WVPASS test ! -e repo
+ WVPASS test ! -e "$HOME/.bup"
+ (export BUP_TEST_SSH_BUP_PATH="$BUP_TEST_OTHER_BUP"
+ WVPASS bup init --remote -:repo
+ validate_repo repo
+ WVPASS test ! -e "$HOME/.bup")
+ WVPASS rm -rf repo
+fi
WVPASS cd "$top"
WVPASS rm -rf "$tmpdir"
--
2.47.3