Re: [StGit PATCH] Check for local changes with "goto"
- From
Karl Hasselström <kha@treskal.com>
- Date
- Jan 30, 2009, 15:26 UTC
- Message-ID
- <20090130152649.GA22044@diana.vm.bytemark.co.uk>
- In-Reply-To
- <b0943d9e0901300601j27ab6ebdq4b38a9f7c0cbe261@mail.gmail.com>
On 2009-01-30 14:01:20 +0000, Catalin Marinas wrote:
Show 18 quoted lines
> @@ -706,9 +706,15 @@ class Index(RunWithEnv):
> ).output_one_line())
> except run.RunException:
> raise MergeException('Conflicting merge')
> - def is_clean(self):
> + def is_clean(self, tree = None):
> + """Check whether the index is clean relative to the given tree."""
> + if tree:
> + sha1 = tree.sha1
> + else:
> + sha1 = 'HEAD'
> try:
> - self.run(['git', 'update-index', '--refresh']).discard_output()
> + self.run(['git', 'diff-index', '--quiet', '--cached', sha1]
> + ).discard_output()
> except run.RunException:
> return False
> else:OK (though I personally would have allowed only Tree objects, with no defaulting to the current HEAD).
The docstring should say s/tree/treeish/.
Show 13 quoted lines
> @@ -858,6 +864,15 @@ class IndexAndWorktree(RunWithEnvCwd): > cmd = ['git', 'update-index', '--remove'] > self.run(cmd + ['-z', '--stdin'] > ).input_nulterm(paths).discard_output() > + def worktree_clean(self): > + """Check whether the worktree is clean relative and no updates or > + merges are needed.""" > + try: > + self.run(['git', 'update-index', '--refresh']).discard_output() > + except run.RunException: > + return False > + else: > + return True
Clean relative to the index.
And what do merges have to do with it?
Show 8 quoted lines
> + # Check for not clean index and worktree
> + if check_clean and iw:
> + if not iw.worktree_clean():
> + self.__halt('Repository not clean. Use "refresh" or '
> + '"status --reset"')
> + elif not iw.index.is_clean()):
> + self.__halt('Index and HEAD different. Use "repair" to '
> + 'recover additional commits')The first message is good, but the second one is misleading -- you'd be much better off just reusing the same message as for the first case. (You could recommend refresh --index if you want to get fancy.)
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle