4_complete_example.xml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <merge_resolver_example>
  2. <scenario>
  3. User provides PR #123 which has merge conflicts between a bugfix branch
  4. and a feature branch that refactored the same code.
  5. </scenario>
  6. <user_request>
  7. #123
  8. </user_request>
  9. <workflow>
  10. <step number="1">
  11. <description>Parse PR number and fetch PR information</description>
  12. <tool_use><![CDATA[
  13. <execute_command>
  14. <command>gh pr view 123 --json title,body,headRefName,baseRefName</command>
  15. </execute_command>
  16. ]]></tool_use>
  17. <expected_output><![CDATA[
  18. {
  19. "title": "Fix memory leak in data processor",
  20. "body": "This PR fixes a memory leak that occurs when processing large datasets. The leak was caused by event listeners not being properly removed.",
  21. "headRefName": "fix/memory-leak",
  22. "baseRefName": "main"
  23. }
  24. ]]></expected_output>
  25. <analysis>
  26. The PR is a bugfix for a memory leak issue. This context will help
  27. prioritize preserving the fix during conflict resolution.
  28. </analysis>
  29. </step>
  30. <step number="2">
  31. <description>Checkout PR branch and prepare for rebase</description>
  32. <tool_use><![CDATA[
  33. <execute_command>
  34. <command>gh pr checkout 123 --force</command>
  35. </execute_command>
  36. ]]></tool_use>
  37. <expected_output><![CDATA[
  38. Switched to branch 'fix/memory-leak'
  39. Your branch is up to date with 'origin/fix/memory-leak'.
  40. ]]></expected_output>
  41. <tool_use><![CDATA[
  42. <execute_command>
  43. <command>git fetch origin main</command>
  44. </execute_command>
  45. ]]></tool_use>
  46. <expected_output><![CDATA[
  47. From github.com:user/repo
  48. * branch main -> FETCH_HEAD
  49. ]]></expected_output>
  50. <tool_use><![CDATA[
  51. <execute_command>
  52. <command>GIT_EDITOR=true git rebase origin/main</command>
  53. </execute_command>
  54. ]]></tool_use>
  55. <expected_output><![CDATA[
  56. Auto-merging src/data/processor.ts
  57. CONFLICT (content): Merge conflict in src/data/processor.ts
  58. Auto-merging src/data/processor.test.ts
  59. CONFLICT (content): Merge conflict in src/data/processor.test.ts
  60. error: could not apply abc123... Fix memory leak in data processor
  61. Resolve all conflicts manually, mark them as resolved with
  62. "git add/rm <conflicted_files>", then run "git rebase --continue".
  63. ]]></expected_output>
  64. </step>
  65. <step number="3">
  66. <description>Check for merge conflicts</description>
  67. <tool_use><![CDATA[
  68. <execute_command>
  69. <command>git status --porcelain | grep "^UU"</command>
  70. </execute_command>
  71. ]]></tool_use>
  72. <expected_output><![CDATA[
  73. UU src/data/processor.ts
  74. UU src/data/processor.test.ts
  75. ]]></expected_output>
  76. <analysis>
  77. Two files have conflicts: the main processor file and its test file.
  78. Both need to be resolved before continuing the rebase.
  79. </analysis>
  80. </step>
  81. <step number="4">
  82. <description>Examine the conflicted processor file</description>
  83. <tool_use><![CDATA[
  84. <read_file>
  85. <path>src/data/processor.ts</path>
  86. </read_file>
  87. ]]></tool_use>
  88. <expected_output><![CDATA[
  89. 45 | export class DataProcessor {
  90. 46 | private listeners: Map<string, EventListener> = new Map();
  91. 47 |
  92. 48 | <<<<<<< HEAD
  93. 49 | async processData(data: DataInput): Promise<ProcessedData> {
  94. 50 | // Refactored to use async/await
  95. 51 | const result = await this.transform(data);
  96. 52 | return result;
  97. 53 | }
  98. 54 | =======
  99. 55 | processData(data: any[]): ProcessedData {
  100. 56 | const listener = this.createListener();
  101. 57 | this.listeners.set(data.id, listener);
  102. 58 |
  103. 59 | return this.transform(data);
  104. 60 | }
  105. 61 | >>>>>>> abc123 (Fix memory leak in data processor)
  106. 62 |
  107. 63 | cleanup() {
  108. 64 | <<<<<<< HEAD
  109. 65 | // TODO: Implement cleanup
  110. 66 | =======
  111. 67 | // Fix: Clear all listeners to prevent memory leak
  112. 68 | this.listeners.forEach(listener => {
  113. 69 | listener.removeAllListeners();
  114. 70 | });
  115. 71 | this.listeners.clear();
  116. 72 | >>>>>>> abc123 (Fix memory leak in data processor)
  117. 73 | }
  118. 74 | }
  119. ]]></expected_output>
  120. </step>
  121. <step number="5">
  122. <description>Analyze the conflicts using git blame</description>
  123. <tool_use><![CDATA[
  124. <execute_command>
  125. <command>git blame -L 49,53 HEAD -- src/data/processor.ts | cut -d' ' -f1 | sort -u | xargs -I {} git log -1 --format="%h %s" {}</command>
  126. </execute_command>
  127. ]]></tool_use>
  128. <expected_output><![CDATA[
  129. def456 Refactor: Convert processData to async/await pattern
  130. ]]></expected_output>
  131. <tool_use><![CDATA[
  132. <execute_command>
  133. <command>git log -1 --format="%h %s" abc123</command>
  134. </execute_command>
  135. ]]></tool_use>
  136. <expected_output><![CDATA[
  137. abc123 Fix: Add listener cleanup to prevent memory leak
  138. ]]></expected_output>
  139. <analysis>
  140. HEAD (main after rebase): Has async/await refactor but missing listener logic
  141. Incoming (bugfix branch): Adds listener tracking and cleanup for memory leak fix
  142. Resolution strategy: Combine both changes - keep async/await refactor
  143. but include the listener tracking and cleanup logic.
  144. </analysis>
  145. </step>
  146. <step number="6">
  147. <description>Resolve the conflicts</description>
  148. <tool_use><![CDATA[
  149. <apply_diff>
  150. <path>src/data/processor.ts</path>
  151. <diff>
  152. <<<<<<< SEARCH
  153. :start_line:48
  154. -------
  155. \<<<<<<< HEAD
  156. async processData(data: DataInput): Promise<ProcessedData> {
  157. // Refactored to use async/await
  158. const result = await this.transform(data);
  159. return result;
  160. }
  161. \=======
  162. processData(data: any[]): ProcessedData {
  163. const listener = this.createListener();
  164. this.listeners.set(data.id, listener);
  165. return this.transform(data);
  166. }
  167. \>>>>>>> abc123 (Fix memory leak in data processor)
  168. =======
  169. async processData(data: DataInput): Promise<ProcessedData> {
  170. // Create and track listener for cleanup (memory leak fix)
  171. const listener = this.createListener();
  172. this.listeners.set(data.id, listener);
  173. // Refactored to use async/await
  174. const result = await this.transform(data);
  175. return result;
  176. }
  177. >>>>>>> REPLACE
  178. <<<<<<< SEARCH
  179. :start_line:63
  180. -------
  181. cleanup() {
  182. \<<<<<<< HEAD
  183. // TODO: Implement cleanup
  184. \=======
  185. // Fix: Clear all listeners to prevent memory leak
  186. this.listeners.forEach(listener => {
  187. listener.removeAllListeners();
  188. });
  189. this.listeners.clear();
  190. \>>>>>>> abc123 (Fix memory leak in data processor)
  191. }
  192. =======
  193. cleanup() {
  194. // Fix: Clear all listeners to prevent memory leak
  195. this.listeners.forEach(listener => {
  196. listener.removeAllListeners();
  197. });
  198. this.listeners.clear();
  199. }
  200. >>>>>>> REPLACE
  201. </diff>
  202. </apply_diff>
  203. ]]></tool_use>
  204. <explanation>
  205. Combined both changes: kept the async/await refactor from main
  206. while preserving the memory leak fix (listener tracking and cleanup)
  207. from the bugfix branch.
  208. </explanation>
  209. </step>
  210. <step number="7">
  211. <description>Resolve test file conflicts</description>
  212. <tool_use><![CDATA[
  213. <read_file>
  214. <path>src/data/processor.test.ts</path>
  215. </read_file>
  216. ]]></tool_use>
  217. <!-- Similar process for test file -->
  218. <tool_use><![CDATA[
  219. <apply_diff>
  220. <path>src/data/processor.test.ts</path>
  221. <diff>
  222. <!-- Test resolution would go here -->
  223. </diff>
  224. </apply_diff>
  225. ]]></tool_use>
  226. </step>
  227. <step number="8">
  228. <description>Stage resolved files and continue rebase</description>
  229. <tool_use><![CDATA[
  230. <execute_command>
  231. <command>git add src/data/processor.ts src/data/processor.test.ts</command>
  232. </execute_command>
  233. ]]></tool_use>
  234. <tool_use><![CDATA[
  235. <execute_command>
  236. <command>GIT_EDITOR=true git rebase --continue</command>
  237. </execute_command>
  238. ]]></tool_use>
  239. <expected_output><![CDATA[
  240. [detached HEAD def789] Fix memory leak in data processor
  241. 2 files changed, 12 insertions(+), 2 deletions(-)
  242. Successfully rebased and updated refs/heads/fix/memory-leak.
  243. ]]></expected_output>
  244. </step>
  245. <step number="9">
  246. <description>Final validation</description>
  247. <tool_use><![CDATA[
  248. <execute_command>
  249. <command>git status</command>
  250. </execute_command>
  251. ]]></tool_use>
  252. <expected_output><![CDATA[
  253. On branch fix/memory-leak
  254. Your branch is ahead of 'origin/fix/memory-leak' by 1 commit.
  255. (use "git push" to publish your local commits)
  256. nothing to commit, working tree clean
  257. ]]></expected_output>
  258. <tool_use><![CDATA[
  259. <execute_command>
  260. <command>git diff origin/main --stat</command>
  261. </execute_command>
  262. ]]></tool_use>
  263. <expected_output><![CDATA[
  264. src/data/processor.ts | 8 ++++++--
  265. src/data/processor.test.ts | 4 ++--
  266. 2 files changed, 8 insertions(+), 4 deletions(-)
  267. ]]></expected_output>
  268. </step>
  269. </workflow>
  270. <completion><![CDATA[
  271. <attempt_completion>
  272. <result>
  273. Successfully resolved merge conflicts for PR #123 "Fix memory leak in data processor".
  274. Resolution Summary:
  275. - src/data/processor.ts: Combined the async/await refactor with the memory leak fix by preserving listener tracking and cleanup logic within the refactored async method
  276. - src/data/processor.test.ts: Updated tests to work with the async implementation while maintaining memory leak test coverage
  277. Both the feature refactor and the critical bugfix have been preserved in the resolution. The rebase has been completed successfully and the branch is ready to be pushed.
  278. </result>
  279. </attempt_completion>
  280. ]]></completion>
  281. <key_takeaways>
  282. <takeaway>Always checkout PR with --force and rebase to reveal conflicts</takeaway>
  283. <takeaway>Fetch PR context to understand the intent of changes</takeaway>
  284. <takeaway>Use git blame and commit messages to understand the history</takeaway>
  285. <takeaway>Combine non-conflicting improvements when possible</takeaway>
  286. <takeaway>Prioritize bugfixes while accommodating refactors</takeaway>
  287. <takeaway>Use GIT_EDITOR=true to ensure non-interactive rebase operations</takeaway>
  288. <takeaway>Complete the rebase process with GIT_EDITOR=true git rebase --continue</takeaway>
  289. <takeaway>Validate that both sets of changes work together</takeaway>
  290. </key_takeaways>
  291. </merge_resolver_example>