From 9eac294517aed1abbe14034e5869610fadf2cfed Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Fri, 4 Jul 2008 00:32:36 -0400 Subject: [PATCH] Implement history --- README | 7 +++---- yap/yap.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/README b/README index 18c4d58..bc29908 100644 --- a/README +++ b/README @@ -21,13 +21,12 @@ TODO: * resolved * remote (list/create) * -d to remove - * history - * amend (amend an arbitrary commit with stash/rebase) - * drop (remove a commit from history) * cherry-pick * -r to apply the opposite * Better commit template message * prepopulate with old commit message after uncommit? * Fixups for running outside root? * staged has full path, unstaged has relative path - + * Handle unmerged files in status + * No commit while rebasing/am + * Fix point with tags diff --git a/yap/yap.py b/yap/yap.py index 21e7aa4..b178681 100644 --- a/yap/yap.py +++ b/yap/yap.py @@ -354,10 +354,53 @@ class Yap(object): os.system("git read-tree HEAD") os.system("git checkout-index -f -a") + os.system("git update-index --refresh") + + def cmd_history(self, subcmd, commit): + "amend | drop " + + if subcmd not in ("amend", "drop"): + raise TypeError + + # XXX: ensure no rebase in progress + + if subcmd == "amend": + # XXX: Use cmd_commit rules + stash = get_output("git stash create") + os.system("git reset --hard") + if not stash: + raise YapError("Failed to stash; no changes?") + + fd, tmpfile = tempfile.mkstemp("yap") + os.close(fd) + try: + os.system("git format-patch -k --stdout '%s' > %s" % (commit, tmpfile)) + if subcmd == "amend": + self.cmd_point(commit, **{'-f': True}) + run_command("git stash apply --index %s" % stash[0]) + # XXX: use cmd_commit instead + os.system("git commit --amend") + stash = get_output("git stash create") + os.system("git reset --hard") + else: + self.cmd_point("%s^" % commit, **{'-f': True}) + + stat = os.stat(tmpfile) + size = stat[6] + if size > 0: + rc = os.system("git am -3 '%s' > /dev/null" % tmpfile) + if (rc): + raise YapError("Failed to apply changes") + + if subcmd == "amend" and stash: + run_command("git stash apply %s" % stash[0]) + finally: + os.unlink(tmpfile) + self.cmd_status() def cmd_usage(self): print >> sys.stderr, "usage: %s " % sys.argv[0] - print >> sys.stderr, " valid commands: init add rm stage unstage status revert commit uncommit log diff branch switch point version" + print >> sys.stderr, " valid commands: init add rm stage unstage status revert commit uncommit log diff branch switch point history version" def main(self, args): if len(args) < 1: -- 2.11.4.GIT