From 3a41e50283bc42a0a67cb2f143fdfb87207cc7ad Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Thu, 3 Jul 2008 23:37:44 -0400 Subject: [PATCH] During uncommit, save away the old log message --- yap/yap.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/yap/yap.py b/yap/yap.py index 8dc7f5f..852131c 100644 --- a/yap/yap.py +++ b/yap/yap.py @@ -140,6 +140,27 @@ class Yap(object): self._assert_file_exists(file) os.system("git checkout-index -f '%s'" % file) + def _parse_commit(self, commit): + lines = get_output("git cat-file commit '%s'" % commit) + commit = {} + + mode = None + for l in lines: + if mode != 'commit' and l.strip() == "": + mode = 'commit' + commit['log'] = [] + continue + if mode == 'commit': + commit['log'].append(l) + continue + + x = l.split(' ') + k = x[0] + v = ' '.join(x[1:]) + commit[k] = v + commit['log'] = '\n'.join(commit['log']) + return commit + def cmd_clone(self, url, directory=""): " [directory]" # XXX: implement in terms of init + remote add + fetch @@ -263,6 +284,18 @@ class Yap(object): self.cmd_status() def cmd_uncommit(self): + commit = self._parse_commit("HEAD") + repo = get_output('git rev-parse --git-dir')[0] + dir = os.path.join(repo, 'yap') + try: + os.mkdir(dir) + except OSError: + pass + msg_file = os.path.join(dir, 'msg') + fd = file(msg_file, 'w') + print >>fd, commit['log'] + fd.close() + tree = get_output("git rev-parse HEAD^") os.system("git update-ref -m uncommit HEAD '%s'" % tree[0]) self.cmd_status() -- 2.11.4.GIT