From: Marc Branchaud <marcn...@xiplink.com>

This makes git-clone consistent with the remote.default support implemented in
git-remote.  Specifically, since "git remote add" sets remote.default if
it's adding the first remote to the repository, when clone itself adds the
first remote it should do the same.

This also makes "git clone -o" work without a special case in the code (so
"git clone /some/repo" and "git clone -o origin /some/repo" produce the same
result).

Signed-off-by: Marc Branchaud <marcn...@xiplink.com>
---
 builtin/clone.c          |  2 ++
 t/t5601-clone.sh         | 10 ++++++++++
 t/t5702-clone-options.sh |  7 +++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index a4d8d25..b198456 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -770,6 +770,8 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
        git_config_set(key.buf, repo);
        strbuf_reset(&key);
 
+       git_config_set("remote.default", option_origin);
+
        if (option_reference.nr)
                setup_reference();
 
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 67869b4..046610d 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -57,6 +57,16 @@ test_expect_success 'clone checks out files' '
 
 '
 
+test_expect_success 'clone sets remote.default' '
+
+       rm -fr dst &&
+       git clone src dst &&
+       (
+               cd dst &&
+               test "$(git config --get remote.default)" = origin
+       )
+'
+
 test_expect_success 'clone respects GIT_WORK_TREE' '
 
        GIT_WORK_TREE=worktree git clone src bare &&
diff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh
index 02cb024..9e573dd 100755
--- a/t/t5702-clone-options.sh
+++ b/t/t5702-clone-options.sh
@@ -15,8 +15,11 @@ test_expect_success 'setup' '
 test_expect_success 'clone -o' '
 
        git clone -o foo parent clone-o &&
-       (cd clone-o && git rev-parse --verify refs/remotes/foo/master)
-
+       (
+               cd clone-o &&
+               git rev-parse --verify refs/remotes/foo/master &&
+               test "$(git config --get remote.default)" = foo
+       )
 '
 
 test_expect_success 'redirected clone' '
-- 
1.7.11.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to