Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 24183:932de135041f
subrepo: warn when adding already tracked files in gitsubrepo
This follows normal Mercurial rules, and the message is lifted from
workingctx.add(). The file is printed with abs() to be consistent with how it
is printed in workingctx, even though that is inconsistent with how added files
are printed in verbose mode. Further, the 'already tracked' notifications come
after all of the files that are added are printed, like in Mercurial.
As a side effect, we now have the reject list to return to the caller, so that
'hg add' exits with the proper code. It looks like an abort occurs if git fails
to add the file. Prior to touching 'snake.python' in the test, this was the
result of attempting to add the file after a 'git rm':
fatal: pathspec 'snake.python' did not match any files
abort: git add error 128 in s (in subrepo s)
I'm not sure what happens when git is a deep subrepo, but the 'in s' and
'in subrepo s' from @annotatesubrepoerror are redundant here. Maybe we should
stat the files before invoking git to catch this case and print out the prettier
hg message? The other thing missing from workingctx.add() is the call to
scmutil.checkportable(), but that would need to borrow the parent's ui object.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 27 Feb 2015 23:30:42 -0500 |
parents | 00ef3edcf1d5 |
children | 6944b64cc28d |
comparison
equal
deleted
inserted
replaced
24182:00ef3edcf1d5 | 24183:932de135041f |
---|---|
1528 return [] | 1528 return [] |
1529 | 1529 |
1530 (modified, added, removed, | 1530 (modified, added, removed, |
1531 deleted, unknown, ignored, clean) = self.status(None) | 1531 deleted, unknown, ignored, clean) = self.status(None) |
1532 | 1532 |
1533 tracked = set() | |
1534 # dirstates 'amn' warn, 'r' is added again | |
1535 for l in (modified, added, deleted, clean): | |
1536 tracked.update(l) | |
1537 | |
1533 # Unknown files not of interest will be rejected by the matcher | 1538 # Unknown files not of interest will be rejected by the matcher |
1534 files = unknown | 1539 files = unknown |
1535 files.extend(match.files()) | 1540 files.extend(match.files()) |
1541 | |
1542 rejected = [] | |
1536 | 1543 |
1537 files = [f for f in sorted(set(files)) if match(f)] | 1544 files = [f for f in sorted(set(files)) if match(f)] |
1538 for f in files: | 1545 for f in files: |
1539 exact = match.exact(f) | 1546 exact = match.exact(f) |
1540 command = ["add"] | 1547 command = ["add"] |
1541 if exact: | 1548 if exact: |
1542 command.append("-f") #should be added, even if ignored | 1549 command.append("-f") #should be added, even if ignored |
1543 if ui.verbose or not exact: | 1550 if ui.verbose or not exact: |
1544 ui.status(_('adding %s\n') % match.rel(f)) | 1551 ui.status(_('adding %s\n') % match.rel(f)) |
1552 | |
1553 if f in tracked: # hg prints 'adding' even if already tracked | |
1554 if exact: | |
1555 rejected.append(f) | |
1556 continue | |
1545 if not opts.get('dry_run'): | 1557 if not opts.get('dry_run'): |
1546 self._gitcommand(command + [f]) | 1558 self._gitcommand(command + [f]) |
1547 return [] | 1559 |
1560 for f in rejected: | |
1561 ui.warn(_("%s already tracked!\n") % match.abs(f)) | |
1562 | |
1563 return rejected | |
1548 | 1564 |
1549 @annotatesubrepoerror | 1565 @annotatesubrepoerror |
1550 def remove(self): | 1566 def remove(self): |
1551 if self._gitmissing(): | 1567 if self._gitmissing(): |
1552 return | 1568 return |