2016-10-20 4 views
0

자식 배열에서 디렉터리 배열을 제거하고 제거 된 각 디렉터리에 대해 1 커밋을 시도합니다. 저는 Rugged와 Gitlab_git (Rugged를 둘러싼 다소 포괄적 인 래퍼)를 사용하고 있으며, 지금까지는 실제로 삭제와 커밋을 제외한 모든 작업을 수행했습니다.트리 제거 및 튼튼한 커밋

전체 트리/디렉토리를 제거하는 방법을 설명하는 Rugged Readme에는 아무것도 표시되지 않습니다. 블롭에 대한 커밋 예제를 사용하고 단일 파일을 디렉토리로 대체하려고 시도했지만 작동하지 않았습니다.

트리 빌더에 대한 코드 편집도 시도했지만 내역에 커밋을 추가하여 을 표시했습니다. 모든 파일이 레포에 추가 된 다음 동일한 작업을 보여주는 스테이징이 남아 있습니다. 아무것도 삭제되지 않았습니다.

oid = repo.write("Removing folder", :blob) 
builder = Rugged::Tree::Builder.new(repo) 
builder << { :type => :blob, :name => "_delete", :oid => oid, :filemode => 0100644 } 

options = {} 
options[:tree] = builder.write 

options[:author] = { :email => "[email protected]", :name => 'Test Author', :time => Time.now } 
options[:committer] = { :email => "te[email protected]", :name => 'Test Author', :time => Time.now } 
options[:message] ||= "Making a commit via Rugged!" 
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact 
options[:update_ref] = 'HEAD' 

Rugged::Commit.create(repo, options) 

의견이 있으십니까? Im은 내부적으로 약간 퍼지기 때문에 내 문제가 될 수 있습니다.

+0

시도하셨습니까? http://www.rubydoc.info/github/libgit2/rugged/Rugged/Index#remove_dir-instance_method? –

답변

2

git 색인은 디렉터리를 명시 적으로 추적하지 않고 그 내용 만 추적합니다. 디렉토리를 제거하려면 해당 디렉토리의 모든 내용을 제거하십시오.

0

리포지토리의 기존 트리를 기반으로 Tree::Builder을 만들 수 있습니다.이 트리를 원하는대로 조작 할 수 있습니다.

parent_commit = ... # e.g. this might be repo.head.target 

# Create a Tree::Builder containing the current commit tree. 
tree_builder = Rugged::Tree::Builder.new(repo, parent_commit.tree) 

# Next remove the directory you want from the Tree::Builder. 
tree_builder.remove('path/to/directory/to/remove') 

# Now create a commit using the contents of the modified tree 
# builder. (You might want to include the :update_ref option here 
# depending on what you are trying to do - something like 
# :update_ref => 'HEAD'.) 
commit_data = {:message => "Remove directory with Rugged", 
    :parents => [commit], 
    :tree => tree_builder.write 
} 

Rugged::Commit.create(repo, commit_data) 

이는 제거 디렉토리와의 repo에 커밋 생성되지만, 업데이트되지 않을 수 있습니다 당신은 이미 당신이 당신의 부모가 커밋해야 할 Commit 객체가있는 경우

, 당신은이 작업을 수행 할 수 있습니다 :update_ref을 사용하지 않은 경우 모든 분기 포인터.

또한 현재 작업 디렉토리 나 색인을 업데이트하지 않습니다. 업데이트하려는 경우 reset을 새로 HEAD으로 만들 수 있지만 작업 손실에주의하십시오. 또는 디렉토리를 직접 제거 할 때 수행 할 작업을 모방 한 Dir.rmdir이라는 디렉토리를 제거하면됩니다.

자세한 내용은 docs을 확인하십시오. 특히 Tree::BuilderCommit.create을 확인하십시오.