From 36a4448ba3bfd3a5d7385b57b4fd7457af28e718 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Tue, 21 Oct 2008 09:18:55 +0200 Subject: [PATCH] Implement most todos. Seems to be working just fine now :) --- src/commands/AmendRecord.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/commands/AmendRecord.cpp b/src/commands/AmendRecord.cpp index e483f2e..1f9d934 100644 --- a/src/commands/AmendRecord.cpp +++ b/src/commands/AmendRecord.cpp @@ -77,7 +77,7 @@ AbstractCommand::ReturnCodes AmendRecord::run() runner.setArguments(arguments); runner.start(GitRunner::WaitUntilFinished); } - if (!oldBranch.isEmpty()) { + if (!deleteBranch.isEmpty()) { arguments.clear(); arguments << "branch" << "-D" << deleteBranch; runner.setArguments(arguments); @@ -103,8 +103,26 @@ AbstractCommand::ReturnCodes AmendRecord::run() return NotInRepo; moveToRoot(); + // create a cursor to walk our patches. CommitsCursor cursor(CommitsCursor::SelectOnePatch); cursor.setUseMatcher(true); + + // use the fact that the cursor already has a commit with 'HEAD' + // search which branch we are on. + foreach (const Branch &branch, m_config.branches()) { + if (branch.commitTreeIsmSha1() == cursor.head().commitTreeIsmSha1()) { + recovery.oldBranch = branch.branchName(); + if (recovery.oldBranch.startsWith("heads/")) + recovery.oldBranch = recovery.oldBranch.mid(6); + break; + } + } + + if (recovery.oldBranch.isEmpty()) { + Logger::error() << "vng Failed: Amend-record requires you to be on a named branch.\n"; + return OtherVngError; + } + Interview interview(cursor, name()); interview.setUsePager(shouldUsePager()); if (! interview.start()) { @@ -157,9 +175,6 @@ AbstractCommand::ReturnCodes AmendRecord::run() if (rc) // this means that the rest will fail, so we have to recover and abort. return rc; - // TODO find the current branch. Possibly using git-for-each-ref refs/heads/ - recovery.oldBranch = "master"; - QString branch; int counter = 0; while(true) { @@ -223,8 +238,15 @@ AbstractCommand::ReturnCodes AmendRecord::run() Logger::error() << "Vng failed: replaying unchanged patches failed, possibly a merge conflict.\n"; return rc; } + recovery.switchedBranch = false; // we are back on our original branch now :) - // TODO cherry-pick the leftData commit + if (! leftData.sha1().isEmpty()) { + arguments.clear(); + arguments << "reset" << "--mixed" << "HEAD^"; + runner.setArguments(arguments); + runner.start(GitRunner::WaitUntilFinished); + } + recovery.oldHead.clear(); return Ok; } -- 2.11.4.GIT