From a844a6cf2301b32c7ac52619368d75573fd3cd4f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 27 Dec 2024 15:32:29 +0000 Subject: [PATCH] repo: put a newline on the .git link file The `.git` file, when containing a `gitdir: ` link, should be suffixed with a trailing newline. --- src/libgit2/repository.c | 2 +- tests/libgit2/repo/init.c | 4 ++-- tests/libgit2/repo/setters.c | 2 +- tests/libgit2/submodule/add.c | 2 +- tests/libgit2/submodule/repository_init.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 82aea517a..d92fe62ff 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -2506,7 +2506,7 @@ static int repo_write_gitlink( error = git_fs_path_make_relative(&path_to_repo, in_dir); if (!error) - error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr); + error = git_str_printf(&buf, "%s %s\n", GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr); if (!error) error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr); diff --git a/tests/libgit2/repo/init.c b/tests/libgit2/repo/init.c index 446ab735e..e23271d35 100644 --- a/tests/libgit2/repo/init.c +++ b/tests/libgit2/repo/init.c @@ -489,7 +489,7 @@ void test_repo_init__relative_gitdir(void) /* Verify gitlink */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git")); - cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr); + cl_assert_equal_s("gitdir: ../my_repository/\n", dot_git_content.ptr); git_str_dispose(&dot_git_content); cleanup_repository("root"); @@ -526,7 +526,7 @@ void test_repo_init__relative_gitdir_2(void) /* Verify gitlink */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git")); - cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr); + cl_assert_equal_s("gitdir: ../my_repository/\n", dot_git_content.ptr); git_str_dispose(&dot_git_content); cleanup_repository("root"); diff --git a/tests/libgit2/repo/setters.c b/tests/libgit2/repo/setters.c index 5c91ed390..1ad38bb8b 100644 --- a/tests/libgit2/repo/setters.c +++ b/tests/libgit2/repo/setters.c @@ -56,7 +56,7 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void) cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git")); cl_assert(git__prefixcmp(git_str_cstr(&content), "gitdir: ") == 0); - cl_assert(git__suffixcmp(git_str_cstr(&content), "testrepo.git/") == 0); + cl_assert(git__suffixcmp(git_str_cstr(&content), "testrepo.git/\n") == 0); git_str_dispose(&content); cl_git_pass(git_repository_config(&cfg, repo)); diff --git a/tests/libgit2/submodule/add.c b/tests/libgit2/submodule/add.c index a2a66e7f5..5208c7fca 100644 --- a/tests/libgit2/submodule/add.c +++ b/tests/libgit2/submodule/add.c @@ -60,7 +60,7 @@ void test_submodule_add__url_absolute(void) /* Verify gitdir path is relative */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_libgit2" "/.git")); - cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/", dot_git_content.ptr); + cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/\n", dot_git_content.ptr); git_repository_free(repo); git_str_dispose(&dot_git_content); diff --git a/tests/libgit2/submodule/repository_init.c b/tests/libgit2/submodule/repository_init.c index 39b55c403..f24ec1d24 100644 --- a/tests/libgit2/submodule/repository_init.c +++ b/tests/libgit2/submodule/repository_init.c @@ -24,7 +24,7 @@ void test_submodule_repository_init__basic(void) /* Verify gitlink */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git")); - cl_assert_equal_s("gitdir: ../.git/modules/sm_gitmodules_only/", dot_git_content.ptr); + cl_assert_equal_s("gitdir: ../.git/modules/sm_gitmodules_only/\n", dot_git_content.ptr); cl_assert(git_fs_path_isfile("submod2/" "sm_gitmodules_only" "/.git"));