Show More
@@ -1280,19 +1280,32 b' def walkchangerevs(repo, match, opts, pr' | |||
|
1280 | 1280 | yield change(rev) |
|
1281 | 1281 | return iterate() |
|
1282 | 1282 | |
|
1283 | def add(ui, repo, match, dryrun): | |
|
1283 | def add(ui, repo, match, dryrun, listsubrepos, prefix): | |
|
1284 | join = lambda f: os.path.join(prefix, f) | |
|
1284 | 1285 | bad = [] |
|
1285 | 1286 | oldbad = match.bad |
|
1286 | 1287 | match.bad = lambda x, y: bad.append(x) or oldbad(x, y) |
|
1287 | 1288 | names = [] |
|
1289 | wctx = repo[None] | |
|
1288 | 1290 | for f in repo.walk(match): |
|
1289 | 1291 | exact = match.exact(f) |
|
1290 | 1292 | if exact or f not in repo.dirstate: |
|
1291 | 1293 | names.append(f) |
|
1292 | 1294 | if ui.verbose or not exact: |
|
1293 | ui.status(_('adding %s\n') % match.rel(f)) | |
|
1295 | ui.status(_('adding %s\n') % match.rel(join(f))) | |
|
1296 | ||
|
1297 | if listsubrepos: | |
|
1298 | for subpath in wctx.substate: | |
|
1299 | sub = wctx.sub(subpath) | |
|
1300 | try: | |
|
1301 | submatch = matchmod.narrowmatcher(subpath, match) | |
|
1302 | bad.extend(sub.add(ui, submatch, dryrun, prefix)) | |
|
1303 | except error.LookupError: | |
|
1304 | ui.status(_("skipping missing subrepository: %s\n") | |
|
1305 | % join(subpath)) | |
|
1306 | ||
|
1294 | 1307 | if not dryrun: |
|
1295 |
rejected = |
|
|
1308 | rejected = wctx.add(names, prefix) | |
|
1296 | 1309 | bad.extend(f for f in rejected if f in match.files()) |
|
1297 | 1310 | return bad |
|
1298 | 1311 |
@@ -47,7 +47,8 b' def add(ui, repo, *pats, **opts):' | |||
|
47 | 47 | """ |
|
48 | 48 | |
|
49 | 49 | m = cmdutil.match(repo, pats, opts) |
|
50 |
rejected = cmdutil.add(ui, repo, m, opts.get('dry_run') |
|
|
50 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), | |
|
51 | opts.get('subrepos'), prefix="") | |
|
51 | 52 | return rejected and 1 or 0 |
|
52 | 53 | |
|
53 | 54 | def addremove(ui, repo, *pats, **opts): |
@@ -4001,7 +4002,8 b' subrepoopts = [' | |||
|
4001 | 4002 | ] |
|
4002 | 4003 | |
|
4003 | 4004 | table = { |
|
4004 |
"^add": (add, walkopts + dryrunopts, |
|
|
4005 | "^add": (add, walkopts + subrepoopts + dryrunopts, | |
|
4006 | _('[OPTION]... [FILE]...')), | |
|
4005 | 4007 | "addremove": |
|
4006 | 4008 | (addremove, similarityopts + walkopts + dryrunopts, |
|
4007 | 4009 | _('[OPTION]... [FILE]...')), |
@@ -769,7 +769,8 b' class workingctx(changectx):' | |||
|
769 | 769 | self.modified() or self.added() or self.removed() or |
|
770 | 770 | (missing and self.deleted())) |
|
771 | 771 | |
|
772 | def add(self, list): | |
|
772 | def add(self, list, prefix=""): | |
|
773 | join = lambda f: os.path.join(prefix, f) | |
|
773 | 774 | wlock = self._repo.wlock() |
|
774 | 775 | ui, ds = self._repo.ui, self._repo.dirstate |
|
775 | 776 | try: |
@@ -779,7 +780,7 b' class workingctx(changectx):' | |||
|
779 | 780 | try: |
|
780 | 781 | st = os.lstat(p) |
|
781 | 782 | except: |
|
782 | ui.warn(_("%s does not exist!\n") % f) | |
|
783 | ui.warn(_("%s does not exist!\n") % join(f)) | |
|
783 | 784 | rejected.append(f) |
|
784 | 785 | continue |
|
785 | 786 | if st.st_size > 10000000: |
@@ -787,13 +788,13 b' class workingctx(changectx):' | |||
|
787 | 788 | "to manage this file\n" |
|
788 | 789 | "(use 'hg revert %s' to cancel the " |
|
789 | 790 | "pending addition)\n") |
|
790 | % (f, 3 * st.st_size // 1000000, f)) | |
|
791 | % (f, 3 * st.st_size // 1000000, join(f))) | |
|
791 | 792 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
792 | 793 | ui.warn(_("%s not added: only files and symlinks " |
|
793 | "supported currently\n") % f) | |
|
794 | "supported currently\n") % join(f)) | |
|
794 | 795 | rejected.append(p) |
|
795 | 796 | elif ds[f] in 'amn': |
|
796 | ui.warn(_("%s already tracked!\n") % f) | |
|
797 | ui.warn(_("%s already tracked!\n") % join(f)) | |
|
797 | 798 | elif ds[f] == 'r': |
|
798 | 799 | ds.normallookup(f) |
|
799 | 800 | else: |
@@ -255,6 +255,8 b' class abstractsubrepo(object):' | |||
|
255 | 255 | """ |
|
256 | 256 | raise NotImplementedError |
|
257 | 257 | |
|
258 | def add(self, ui, match, dryrun, prefix): | |
|
259 | return [] | |
|
258 | 260 | |
|
259 | 261 | def status(self, rev2, **opts): |
|
260 | 262 | return [], [], [], [], [], [], [] |
@@ -291,6 +293,10 b' class hgsubrepo(abstractsubrepo):' | |||
|
291 | 293 | addpathconfig('default-push', defpushpath) |
|
292 | 294 | fp.close() |
|
293 | 295 | |
|
296 | def add(self, ui, match, dryrun, prefix): | |
|
297 | return cmdutil.add(ui, self._repo, match, dryrun, True, | |
|
298 | os.path.join(prefix, self._path)) | |
|
299 | ||
|
294 | 300 | def status(self, rev2, **opts): |
|
295 | 301 | try: |
|
296 | 302 | rev1 = self._state[1] |
@@ -176,7 +176,7 b' Show an error if we use --options with a' | |||
|
176 | 176 | |
|
177 | 177 | Show all commands + options |
|
178 | 178 | $ hg debugcommands |
|
179 | add: include, exclude, dry-run | |
|
179 | add: include, exclude, subrepos, dry-run | |
|
180 | 180 | annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, include, exclude |
|
181 | 181 | clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd |
|
182 | 182 | commit: addremove, close-branch, include, exclude, message, logfile, date, user |
@@ -274,6 +274,7 b' Test short command list with verbose opt' | |||
|
274 | 274 | |
|
275 | 275 | -I --include PATTERN [+] include names matching the given patterns |
|
276 | 276 | -X --exclude PATTERN [+] exclude names matching the given patterns |
|
277 | -S --subrepos recurse into subrepositories | |
|
277 | 278 | -n --dry-run do not perform actions, just print output |
|
278 | 279 | |
|
279 | 280 | [+] marked option can be specified multiple times |
@@ -312,6 +313,7 b' Verbose help for add' | |||
|
312 | 313 | |
|
313 | 314 | -I --include PATTERN [+] include names matching the given patterns |
|
314 | 315 | -X --exclude PATTERN [+] exclude names matching the given patterns |
|
316 | -S --subrepos recurse into subrepositories | |
|
315 | 317 | -n --dry-run do not perform actions, just print output |
|
316 | 318 | |
|
317 | 319 | global options: |
@@ -364,6 +366,7 b' Test help option with version option' | |||
|
364 | 366 | |
|
365 | 367 | -I --include PATTERN [+] include names matching the given patterns |
|
366 | 368 | -X --exclude PATTERN [+] exclude names matching the given patterns |
|
369 | -S --subrepos recurse into subrepositories | |
|
367 | 370 | -n --dry-run do not perform actions, just print output |
|
368 | 371 | |
|
369 | 372 | [+] marked option can be specified multiple times |
@@ -391,6 +394,7 b' Test help option with version option' | |||
|
391 | 394 | |
|
392 | 395 | -I --include PATTERN [+] include names matching the given patterns |
|
393 | 396 | -X --exclude PATTERN [+] exclude names matching the given patterns |
|
397 | -S --subrepos recurse into subrepositories | |
|
394 | 398 | -n --dry-run do not perform actions, just print output |
|
395 | 399 | |
|
396 | 400 | [+] marked option can be specified multiple times |
@@ -8,25 +8,30 b' Create test repository:' | |||
|
8 | 8 | |
|
9 | 9 | $ hg init |
|
10 | 10 | $ echo x1 > x.txt |
|
11 | $ hg add x.txt | |
|
12 | 11 | |
|
13 | 12 | $ hg init foo |
|
14 | 13 | $ cd foo |
|
15 | 14 | $ echo y1 > y.txt |
|
16 | $ hg add y.txt | |
|
17 | 15 | |
|
18 | 16 | $ hg init bar |
|
19 | 17 | $ cd bar |
|
20 | 18 | $ echo z1 > z.txt |
|
21 | $ hg add z.txt | |
|
22 | 19 | |
|
23 | 20 | $ cd .. |
|
24 | 21 | $ echo 'bar = bar' > .hgsub |
|
25 | $ hg add .hgsub | |
|
26 | 22 | |
|
27 | 23 | $ cd .. |
|
28 | 24 | $ echo 'foo = foo' > .hgsub |
|
29 | $ hg add .hgsub | |
|
25 | ||
|
26 | Add files --- .hgsub files must go first to trigger subrepos: | |
|
27 | ||
|
28 | $ hg add -S .hgsub | |
|
29 | $ hg add -S foo/.hgsub | |
|
30 | $ hg add -S foo/bar | |
|
31 | adding foo/bar/z.txt | |
|
32 | $ hg add -S | |
|
33 | adding x.txt | |
|
34 | adding foo/y.txt | |
|
30 | 35 | |
|
31 | 36 | Test recursive status without committing anything: |
|
32 | 37 |
General Comments 0
You need to be logged in to leave comments.
Login now