0
按我最近的問題上merging branches using GitPython,我試圖單元測試解決方案出現。要做到這一點,我需要模擬用戶打開他們的合併工具,解決衝突和提交的結果。如何以編程方式模擬解決與GitPython合併衝突?
如果我做到這一點使用這一切似乎工作CLI手動:
echo 'Something to resolve the conflict' > conflicted_file.txt
git add conflicted_file.txt
git commit -m "Conflict resolved"
我試着用GitPython來模擬相同的過程:
filename = 'conflicted_file.txt"
with open(filename, 'w') as f:
f.write('Some combined content which resolves the merge issue')
# repo is a git.Repo instance
repo.index.add([filename])
repo.index.commit("Simulating user resolving a conflict"+filename)
..但是這只是提高我的一個例外:
Traceback (most recent call last):
File "C:\Projects\grit\test_Gritter.py", line 240, in test_MergeConflicts
repo.index.commit("Simulating user resolving a conflict"+filename)
File "C:\Python34\lib\site-packages\git\index\base.py", line 934, in commit
tree = self.write_tree()
File "C:\Python34\lib\site-packages\git\index\base.py", line 531, in write_tree
binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries)))
File "C:\Python34\lib\site-packages\git\index\fun.py", line 234, in write_tree_from_cache
raise UnmergedEntriesError(entry)
git.exc.UnmergedEntriesError: 100644 fd05580faebf11aee13944da595112eced471664 2 conflicted_file.txt
有沒有別的東西,我需要將其標記爲已解決?
編輯 - 什麼我試圖自動化
一些背景,因此只是要清楚,我想讓它儘可能容易合併已經更新到遠程主分支的變化遠程功能分支,解決任何合併衝突。
據我所知,做正確的方法是:
- 創建本地特性分支
- 進行一些更改
- 把我的更改遠程
- ...同時別人合併他們的更改到遠程主機,以便我現在需要將這些更改合併到我的特性分支...
- 切換到主站(在我的本地結賬) 從遠程主
- 拉來更新我的本地副本
- 切換到我的本地特性分支
- 試圖合併
- 解決任何衝突
- 推合併到遠程特性分支
我現在已經在一個Python腳本中獲得了大部分內容,但是這個問題所涉及的問題是在上面的步驟中模擬步驟9。
它也過於複雜,Git有更多的6種不同的方式來合併和解決衝突....你確定你想這樣做:-) – CodeWizard
爲了澄清,我不想在腳本中處理衝突解決方案,用戶必須這樣做,但是需要從遠程主服務器中提取更改,將這些更改合併到我的功能分支中,然後暫停解決衝突,然後推送結果進入遠程分支...是我一直在做一遍又一遍,所以我一直在開發這個腳本,以減少所有的輸入:) –
什麼錯:'git pull ... --rebase'?它會自動下載併合並你的代碼。它會停止,如果你有衝突 – CodeWizard