Skip to content

Commit 9961198

Browse files
authored
Merge pull request libgit2#6982 from libgit2/ethomson/no_dotgit_for_separate_workdir
No `.git` for separate workdir
2 parents e9d97be + ca2a241 commit 9961198

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

include/git2/deprecated.h

+11
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,17 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
748748

749749
/**@}*/
750750

751+
/** @name Deprecated Repository Constants
752+
*
753+
* These enumeration values are retained for backward compatibility.
754+
*/
755+
756+
/**
757+
* @deprecated This option is deprecated; it is now implied when
758+
* a separate working directory is specified to `git_repository_init`.
759+
*/
760+
#define GIT_REPOSITORY_INIT_NO_DOTGIT_DIR 0
761+
751762
/** @name Deprecated Revspec Constants
752763
*
753764
* These enumeration values are retained for backward compatibility.

include/git2/repository.h

-7
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,6 @@ typedef enum {
258258
*/
259259
GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1),
260260

261-
/**
262-
* Normally a "/.git/" will be appended to the repo path for
263-
* non-bare repos (if it is not already there), but passing this flag
264-
* prevents that behavior.
265-
*/
266-
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2),
267-
268261
/**
269262
* Make the repo_path (and workdir_path) as needed. Init is always willing
270263
* to create the ".git" directory even without this flag. This flag tells

src/cli/cmd_init.c

-2
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ int cmd_init(int argc, char **argv)
8282
init_opts.initial_head = branch;
8383

8484
if (git_dir) {
85-
init_opts.flags |= GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
8685
init_opts.workdir_path = path;
87-
8886
repo_path = git_dir;
8987
} else {
9088
repo_path = path;

src/libgit2/repository.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -2690,8 +2690,7 @@ static int repo_init_directories(
26902690
is_bare = ((opts->flags & GIT_REPOSITORY_INIT_BARE) != 0);
26912691

26922692
add_dotgit =
2693-
(opts->flags & GIT_REPOSITORY_INIT_NO_DOTGIT_DIR) == 0 &&
2694-
!is_bare &&
2693+
!is_bare && !opts->workdir_path &&
26952694
git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
26962695
git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
26972696

src/libgit2/submodule.c

-2
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ static int submodule_repo_init(
757757

758758
initopt.workdir_path = workdir.ptr;
759759
initopt.flags |=
760-
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR |
761760
GIT_REPOSITORY_INIT_RELATIVE_GITLINK;
762761

763762
error = git_repository_init_ext(&subrepo, repodir.ptr, &initopt);
@@ -1289,7 +1288,6 @@ static int submodule_repo_create(
12891288
initopt.flags =
12901289
GIT_REPOSITORY_INIT_MKPATH |
12911290
GIT_REPOSITORY_INIT_NO_REINIT |
1292-
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR |
12931291
GIT_REPOSITORY_INIT_RELATIVE_GITLINK;
12941292

12951293
/* Workdir: path to sub-repo working directory */

tests/libgit2/repo/init.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ void test_repo_init__extended_1(void)
425425
struct stat st;
426426
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
427427

428-
opts.flags = GIT_REPOSITORY_INIT_MKPATH |
429-
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
428+
opts.flags = GIT_REPOSITORY_INIT_MKPATH;
430429
opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
431430
opts.workdir_path = "../c_wd";
432431
opts.description = "Awesomest test repository evah";
@@ -466,16 +465,18 @@ void test_repo_init__extended_1(void)
466465
void test_repo_init__relative_gitdir(void)
467466
{
468467
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
468+
git_str head_content = GIT_STR_INIT;
469469
git_str dot_git_content = GIT_STR_INIT;
470470

471471
opts.workdir_path = "../c_wd";
472472
opts.flags =
473473
GIT_REPOSITORY_INIT_MKPATH |
474-
GIT_REPOSITORY_INIT_RELATIVE_GITLINK |
475-
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
474+
GIT_REPOSITORY_INIT_RELATIVE_GITLINK;
476475

477476
/* make the directory first, then it should succeed */
478477
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
478+
cl_git_pass(git_futils_readbuffer(&head_content, "root/b/my_repository/HEAD"));
479+
cl_assert_equal_s("ref: refs/heads/master\n", head_content.ptr);
479480

480481
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
481482
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
@@ -491,6 +492,7 @@ void test_repo_init__relative_gitdir(void)
491492
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
492493
cl_assert_equal_s("gitdir: ../my_repository/\n", dot_git_content.ptr);
493494

495+
git_str_dispose(&head_content);
494496
git_str_dispose(&dot_git_content);
495497
cleanup_repository("root");
496498
}
@@ -507,8 +509,7 @@ void test_repo_init__relative_gitdir_2(void)
507509
opts.workdir_path = full_path.ptr;
508510
opts.flags =
509511
GIT_REPOSITORY_INIT_MKPATH |
510-
GIT_REPOSITORY_INIT_RELATIVE_GITLINK |
511-
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
512+
GIT_REPOSITORY_INIT_RELATIVE_GITLINK;
512513

513514
/* make the directory first, then it should succeed */
514515
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));

0 commit comments

Comments
 (0)