libgit2 C API를 사용하여 두 개의 git 저장소 (이름이 repo 및 module)를 코드에 성공적으로 만들고 "모듈" 리포지토리를 서브 모듈로 "repo"리포지토리에 저장합니다. libgit2 git_submodule_add_setup C API를 사용하여이 작업을 수행하려고합니다. https://libgit2.github.com/libgit2/#HEAD/group/submodule/git_submodule_add_setup을 참조하십시오.libgit2를 사용하여 코드에서 수퍼 프로젝트에 git 하위 모듈을 추가하는 방법
git_submodule_add_setup : 이가 인출 및 서브 모듈 내용의 체크 아웃에 "자식 서브 모듈 추가"않습니다
문서는이 다음 말했다. 새로운 서브 모듈을 준비하고 .gitmodules에 엔트리를 만들고 작업 디렉토리의 주어진 경로 또는 작업 디렉토리에서 새로운 저장소로의 git 링크를 가진 .git/modules에 빈 초기화 된 저장소를 만듭니다.
"git submodule add"를 완전히 에뮬레이션하려면이 함수를 호출 한 다음 submodule repo를 열고 필요에 따라 복제 단계를 수행하십시오.. 마지막으로 git_submodule_add_finalize()를 호출하여 새 하위 모듈을 추가하고 .git 모듈을 인덱스에 추가하여 커밋 준비를 완료합니다.
제 질문은 git_submodule_add_setup에 대한 호출이 초기화되었지만 비어있는 하위 모듈 (그 내부에 .git 디렉토리가 있음)을 만들었 으면 위에서 언급 한 복제 작업을 얼마나 정확하게 수행합니까? 이미 git_submodule_open 및 git_clone C API를 사용하여 복제본을 여러 번 만들었지 만 아무 소용이 없습니다. 하위 모듈이 빈 폴더가 아니기 때문에 복제가 실패합니다. git_clone C API 문서를 읽었고 https://libgit2.github.com/docs/guides/101-samples/#repositories_clone_simple 등의 예제 코드에 익숙해졌지만 여전히 현명한 사람은 아닙니다. 알고있는 사람들의 도움을 많이 주시면 감사하겠습니다.
나는 지금까지 가지고있는 것의 맛을 내기 위해 아래 코드 스 니펫을 포함 시켰습니다.
namespace bfs = boost::filesystem;
git_repository * repo = NULL;
bfs::path const repo_path = bfs::current_path()/"repo";
std::string const repo_url = repo_path.string();
git_repository_init(&repo, repo_url.c_str(), 0);
//Add various files to repo index, and commit them...
git_repository * module = NULL;
bfs::path const module_path = bfs::current_path()/"module";
std::string const module_url = module_path.string();
git_repository_init(&module, module_url.c_str(), 0);
//Add various files to moduleindex, and commit them...
git_submodule * submodule = NULL;
git_submodule_add_setup(&submodule, repo, module_url.c_str(), "module", 0);
//What do I need to do in here to clone the module into position??
git_submodule_add_finalize(submodule);
git_submodule_free(submodule);
git_repository_free(module);
git_repository_free(repo);
답변이 잘못되었습니다. ( –