comparison mercurial/commands.py @ 4777:44e17f5029d0

Make hg add foo; hg mv foo bar work. - foo will be removed (the user has a copy of its contents in bar) - bar will not be marked as a copy (there was no committed version of foo). We print a warning telling that to the user. Fixes issue269.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 03 Jul 2007 03:06:40 -0300
parents c41a404ac387
children 452d171a1b39
comparison
equal deleted inserted replaced
4776:719c402258ee 4777:44e17f5029d0
464 # abs: hgsep 464 # abs: hgsep
465 # rel: ossep 465 # rel: ossep
466 # return: hgsep 466 # return: hgsep
467 def okaytocopy(abs, rel, exact): 467 def okaytocopy(abs, rel, exact):
468 reasons = {'?': _('is not managed'), 468 reasons = {'?': _('is not managed'),
469 'a': _('has been marked for add'),
470 'r': _('has been marked for remove')} 469 'r': _('has been marked for remove')}
471 state = repo.dirstate.state(abs) 470 state = repo.dirstate.state(abs)
472 reason = reasons.get(state) 471 reason = reasons.get(state)
473 if reason: 472 if reason:
473 if exact:
474 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
475 else:
474 if state == 'a': 476 if state == 'a':
475 origsrc = repo.dirstate.copied(abs) 477 origsrc = repo.dirstate.copied(abs)
476 if origsrc is not None: 478 if origsrc is not None:
477 return origsrc 479 return origsrc
478 if exact:
479 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
480 else:
481 return abs 480 return abs
482 481
483 # origsrc: hgsep 482 # origsrc: hgsep
484 # abssrc: hgsep 483 # abssrc: hgsep
485 # relsrc: ossep 484 # relsrc: ossep
530 errors += 1 529 errors += 1
531 return 530 return
532 if ui.verbose or not exact: 531 if ui.verbose or not exact:
533 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) 532 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
534 targets[abstarget] = abssrc 533 targets[abstarget] = abssrc
535 if abstarget != origsrc and not opts.get('dry_run'): 534 if abstarget != origsrc:
536 repo.copy(origsrc, abstarget, wlock) 535 if repo.dirstate.state(origsrc) == 'a':
536 ui.warn(_("%s was marked for addition. "
537 "%s will not be committed as a copy.\n")
538 % (repo.pathto(origsrc, cwd), reltarget))
539 if abstarget not in repo.dirstate and not opts.get('dry_run'):
540 repo.add([abstarget], wlock)
541 elif not opts.get('dry_run'):
542 repo.copy(origsrc, abstarget, wlock)
537 copied.append((abssrc, relsrc, exact)) 543 copied.append((abssrc, relsrc, exact))
538 544
539 # pat: ossep 545 # pat: ossep
540 # dest ossep 546 # dest ossep
541 # srcs: list of (hgsep, hgsep, ossep, bool) 547 # srcs: list of (hgsep, hgsep, ossep, bool)