diff options
author | Russell Belfer <rb@github.com> | 2013-06-21 11:51:16 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-06-21 11:55:13 -0700 |
commit | 9094ae5a3c12ee99743498cb8e895d18b932e4dd (patch) | |
tree | d9018379bf5d6b784681f256ebd5186e0662688f /tests-clar/checkout/index.c | |
parent | 00197c34d6385a2de3970c9f820714064c5bf27f (diff) | |
download | libgit2-9094ae5a3c12ee99743498cb8e895d18b932e4dd.tar.gz |
Add target directory to checkout
This adds the ability for checkout to write to a target directory
instead of having to use the working directory of the repository.
This makes it easier to do exports of repository data and the like.
This is similar to, but not quite the same as, the --prefix option
to `git checkout-index` (this will always be treated as a directory
name, not just as a simple text prefix).
As part of this, the workdir iterator was extended to take the
path to the working directory as a parameter and fallback on the
git_repository_workdir result only if it's not specified.
Fixes #1332
Diffstat (limited to 'tests-clar/checkout/index.c')
-rw-r--r-- | tests-clar/checkout/index.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c index a3a0f8fda..16584ce22 100644 --- a/tests-clar/checkout/index.c +++ b/tests-clar/checkout/index.c @@ -506,3 +506,31 @@ void test_checkout_index__issue_1397(void) check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf"); } + +void test_checkout_index__target_directory(void) +{ + git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; + checkout_counts cts; + memset(&cts, 0, sizeof(cts)); + + opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; + opts.target_directory = "alternative"; + + opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL; + opts.notify_cb = checkout_count_callback; + opts.notify_payload = &cts; + + /* create some files that *would* conflict if we were using the wd */ + cl_git_mkfile("testrepo/README", "I'm in the way!\n"); + cl_git_mkfile("testrepo/new.txt", "my new file\n"); + + cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); + + cl_assert_equal_i(0, cts.n_untracked); + cl_assert_equal_i(0, cts.n_ignored); + cl_assert_equal_i(4, cts.n_updates); + + check_file_contents("./alternative/README", "hey there\n"); + check_file_contents("./alternative/branch_file.txt", "hi\nbye!\n"); + check_file_contents("./alternative/new.txt", "my new file\n"); +} |