diff options
author | LaMont Jones <lamontjones@google.com> | 2022-06-22 19:21:15 +0000 |
---|---|---|
committer | LaMont Jones <lamontjones@google.com> | 2022-07-14 16:00:18 +0000 |
commit | 8501d4602a4c85f1e22c7a51ad191af8166efecd (patch) | |
tree | e8c5bf46c22f029412b35fc48c04daed73cde633 /project.py | |
parent | 8db78c7d4db84ff9e191457bbf4b1254da321c7e (diff) | |
download | git-repo-8501d4602a4c85f1e22c7a51ad191af8166efecd.tar.gz |
status, diff: display correct path for multi-manifest
Display the project path relative to the outermost manifest by default,
and relative to the sub manifest only when --this-manifest-only is
specified.
For project-related diagnostic messages, use the outermost manifest for
messages.
Change-Id: I4537d7dd412a2c182e77d6720e95c1b0ef70eb0e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/340754
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: LaMont Jones <lamontjones@google.com>
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 43 |
1 files changed, 24 insertions, 19 deletions
@@ -794,19 +794,22 @@ class Project(object): | |||
794 | """ | 794 | """ |
795 | return bool(self.UncommitedFiles(get_all=False)) | 795 | return bool(self.UncommitedFiles(get_all=False)) |
796 | 796 | ||
797 | def PrintWorkTreeStatus(self, output_redir=None, quiet=False): | 797 | def PrintWorkTreeStatus(self, output_redir=None, quiet=False, local=False): |
798 | """Prints the status of the repository to stdout. | 798 | """Prints the status of the repository to stdout. |
799 | 799 | ||
800 | Args: | 800 | Args: |
801 | output_redir: If specified, redirect the output to this object. | 801 | output_redir: If specified, redirect the output to this object. |
802 | quiet: If True then only print the project name. Do not print | 802 | quiet: If True then only print the project name. Do not print |
803 | the modified files, branch name, etc. | 803 | the modified files, branch name, etc. |
804 | local: a boolean, if True, the path is relative to the local | ||
805 | (sub)manifest. If false, the path is relative to the | ||
806 | outermost manifest. | ||
804 | """ | 807 | """ |
805 | if not platform_utils.isdir(self.worktree): | 808 | if not platform_utils.isdir(self.worktree): |
806 | if output_redir is None: | 809 | if output_redir is None: |
807 | output_redir = sys.stdout | 810 | output_redir = sys.stdout |
808 | print(file=output_redir) | 811 | print(file=output_redir) |
809 | print('project %s/' % self.relpath, file=output_redir) | 812 | print('project %s/' % self.RelPath(local), file=output_redir) |
810 | print(' missing (run "repo sync")', file=output_redir) | 813 | print(' missing (run "repo sync")', file=output_redir) |
811 | return | 814 | return |
812 | 815 | ||
@@ -824,7 +827,7 @@ class Project(object): | |||
824 | out = StatusColoring(self.config) | 827 | out = StatusColoring(self.config) |
825 | if output_redir is not None: | 828 | if output_redir is not None: |
826 | out.redirect(output_redir) | 829 | out.redirect(output_redir) |
827 | out.project('project %-40s', self.relpath + '/ ') | 830 | out.project('project %-40s', self.RelPath(local) + '/ ') |
828 | 831 | ||
829 | if quiet: | 832 | if quiet: |
830 | out.nl() | 833 | out.nl() |
@@ -885,7 +888,8 @@ class Project(object): | |||
885 | 888 | ||
886 | return 'DIRTY' | 889 | return 'DIRTY' |
887 | 890 | ||
888 | def PrintWorkTreeDiff(self, absolute_paths=False, output_redir=None): | 891 | def PrintWorkTreeDiff(self, absolute_paths=False, output_redir=None, |
892 | local=False): | ||
889 | """Prints the status of the repository to stdout. | 893 | """Prints the status of the repository to stdout. |
890 | """ | 894 | """ |
891 | out = DiffColoring(self.config) | 895 | out = DiffColoring(self.config) |
@@ -896,8 +900,8 @@ class Project(object): | |||
896 | cmd.append('--color') | 900 | cmd.append('--color') |
897 | cmd.append(HEAD) | 901 | cmd.append(HEAD) |
898 | if absolute_paths: | 902 | if absolute_paths: |
899 | cmd.append('--src-prefix=a/%s/' % self.relpath) | 903 | cmd.append('--src-prefix=a/%s/' % self.RelPath(local)) |
900 | cmd.append('--dst-prefix=b/%s/' % self.relpath) | 904 | cmd.append('--dst-prefix=b/%s/' % self.RelPath(local)) |
901 | cmd.append('--') | 905 | cmd.append('--') |
902 | try: | 906 | try: |
903 | p = GitCommand(self, | 907 | p = GitCommand(self, |
@@ -907,14 +911,14 @@ class Project(object): | |||
907 | p.Wait() | 911 | p.Wait() |
908 | except GitError as e: | 912 | except GitError as e: |
909 | out.nl() | 913 | out.nl() |
910 | out.project('project %s/' % self.relpath) | 914 | out.project('project %s/' % self.RelPath(local)) |
911 | out.nl() | 915 | out.nl() |
912 | out.fail('%s', str(e)) | 916 | out.fail('%s', str(e)) |
913 | out.nl() | 917 | out.nl() |
914 | return False | 918 | return False |
915 | if p.stdout: | 919 | if p.stdout: |
916 | out.nl() | 920 | out.nl() |
917 | out.project('project %s/' % self.relpath) | 921 | out.project('project %s/' % self.RelPath(local)) |
918 | out.nl() | 922 | out.nl() |
919 | out.write('%s', p.stdout) | 923 | out.write('%s', p.stdout) |
920 | return p.Wait() == 0 | 924 | return p.Wait() == 0 |
@@ -1553,14 +1557,14 @@ class Project(object): | |||
1553 | if self.IsDirty(): | 1557 | if self.IsDirty(): |
1554 | if force: | 1558 | if force: |
1555 | print('warning: %s: Removing dirty project: uncommitted changes lost.' % | 1559 | print('warning: %s: Removing dirty project: uncommitted changes lost.' % |
1556 | (self.relpath,), file=sys.stderr) | 1560 | (self.RelPath(local=False),), file=sys.stderr) |
1557 | else: | 1561 | else: |
1558 | print('error: %s: Cannot remove project: uncommitted changes are ' | 1562 | print('error: %s: Cannot remove project: uncommitted changes are ' |
1559 | 'present.\n' % (self.relpath,), file=sys.stderr) | 1563 | 'present.\n' % (self.RelPath(local=False),), file=sys.stderr) |
1560 | return False | 1564 | return False |
1561 | 1565 | ||
1562 | if not quiet: | 1566 | if not quiet: |
1563 | print('%s: Deleting obsolete checkout.' % (self.relpath,)) | 1567 | print('%s: Deleting obsolete checkout.' % (self.RelPath(local=False),)) |
1564 | 1568 | ||
1565 | # Unlock and delink from the main worktree. We don't use git's worktree | 1569 | # Unlock and delink from the main worktree. We don't use git's worktree |
1566 | # remove because it will recursively delete projects -- we handle that | 1570 | # remove because it will recursively delete projects -- we handle that |
@@ -1599,7 +1603,8 @@ class Project(object): | |||
1599 | if e.errno != errno.ENOENT: | 1603 | if e.errno != errno.ENOENT: |
1600 | print('error: %s: %s' % (self.gitdir, e), file=sys.stderr) | 1604 | print('error: %s: %s' % (self.gitdir, e), file=sys.stderr) |
1601 | print('error: %s: Failed to delete obsolete checkout; remove manually, ' | 1605 | print('error: %s: Failed to delete obsolete checkout; remove manually, ' |
1602 | 'then run `repo sync -l`.' % (self.relpath,), file=sys.stderr) | 1606 | 'then run `repo sync -l`.' % (self.RelPath(local=False),), |
1607 | file=sys.stderr) | ||
1603 | return False | 1608 | return False |
1604 | 1609 | ||
1605 | # Delete everything under the worktree, except for directories that contain | 1610 | # Delete everything under the worktree, except for directories that contain |
@@ -1635,7 +1640,7 @@ class Project(object): | |||
1635 | print('error: %s: Failed to remove: %s' % (d, e), file=sys.stderr) | 1640 | print('error: %s: Failed to remove: %s' % (d, e), file=sys.stderr) |
1636 | failed = True | 1641 | failed = True |
1637 | if failed: | 1642 | if failed: |
1638 | print('error: %s: Failed to delete obsolete checkout.' % (self.relpath,), | 1643 | print('error: %s: Failed to delete obsolete checkout.' % (self.RelPath(local=False),), |
1639 | file=sys.stderr) | 1644 | file=sys.stderr) |
1640 | print(' Remove manually, then run `repo sync -l`.', file=sys.stderr) | 1645 | print(' Remove manually, then run `repo sync -l`.', file=sys.stderr) |
1641 | return False | 1646 | return False |
@@ -2050,7 +2055,7 @@ class Project(object): | |||
2050 | def _FetchArchive(self, tarpath, cwd=None): | 2055 | def _FetchArchive(self, tarpath, cwd=None): |
2051 | cmd = ['archive', '-v', '-o', tarpath] | 2056 | cmd = ['archive', '-v', '-o', tarpath] |
2052 | cmd.append('--remote=%s' % self.remote.url) | 2057 | cmd.append('--remote=%s' % self.remote.url) |
2053 | cmd.append('--prefix=%s/' % self.relpath) | 2058 | cmd.append('--prefix=%s/' % self.RelPath(local=False)) |
2054 | cmd.append(self.revisionExpr) | 2059 | cmd.append(self.revisionExpr) |
2055 | 2060 | ||
2056 | command = GitCommand(self, cmd, cwd=cwd, | 2061 | command = GitCommand(self, cmd, cwd=cwd, |
@@ -2634,7 +2639,7 @@ class Project(object): | |||
2634 | if not filecmp.cmp(stock_hook, dst, shallow=False): | 2639 | if not filecmp.cmp(stock_hook, dst, shallow=False): |
2635 | if not quiet: | 2640 | if not quiet: |
2636 | _warn("%s: Not replacing locally modified %s hook", | 2641 | _warn("%s: Not replacing locally modified %s hook", |
2637 | self.relpath, name) | 2642 | self.RelPath(local=False), name) |
2638 | continue | 2643 | continue |
2639 | try: | 2644 | try: |
2640 | platform_utils.symlink( | 2645 | platform_utils.symlink( |
@@ -2729,7 +2734,7 @@ class Project(object): | |||
2729 | 'work tree. If you\'re comfortable with the ' | 2734 | 'work tree. If you\'re comfortable with the ' |
2730 | 'possibility of losing the work tree\'s git metadata,' | 2735 | 'possibility of losing the work tree\'s git metadata,' |
2731 | ' use `repo sync --force-sync {0}` to ' | 2736 | ' use `repo sync --force-sync {0}` to ' |
2732 | 'proceed.'.format(self.relpath)) | 2737 | 'proceed.'.format(self.RelPath(local=False))) |
2733 | 2738 | ||
2734 | def _ReferenceGitDir(self, gitdir, dotgit, copy_all): | 2739 | def _ReferenceGitDir(self, gitdir, dotgit, copy_all): |
2735 | """Update |dotgit| to reference |gitdir|, using symlinks where possible. | 2740 | """Update |dotgit| to reference |gitdir|, using symlinks where possible. |
@@ -3209,7 +3214,7 @@ class _InfoMessage(object): | |||
3209 | self.text = text | 3214 | self.text = text |
3210 | 3215 | ||
3211 | def Print(self, syncbuf): | 3216 | def Print(self, syncbuf): |
3212 | syncbuf.out.info('%s/: %s', self.project.relpath, self.text) | 3217 | syncbuf.out.info('%s/: %s', self.project.RelPath(local=False), self.text) |
3213 | syncbuf.out.nl() | 3218 | syncbuf.out.nl() |
3214 | 3219 | ||
3215 | 3220 | ||
@@ -3221,7 +3226,7 @@ class _Failure(object): | |||
3221 | 3226 | ||
3222 | def Print(self, syncbuf): | 3227 | def Print(self, syncbuf): |
3223 | syncbuf.out.fail('error: %s/: %s', | 3228 | syncbuf.out.fail('error: %s/: %s', |
3224 | self.project.relpath, | 3229 | self.project.RelPath(local=False), |
3225 | str(self.why)) | 3230 | str(self.why)) |
3226 | syncbuf.out.nl() | 3231 | syncbuf.out.nl() |
3227 | 3232 | ||
@@ -3234,7 +3239,7 @@ class _Later(object): | |||
3234 | 3239 | ||
3235 | def Run(self, syncbuf): | 3240 | def Run(self, syncbuf): |
3236 | out = syncbuf.out | 3241 | out = syncbuf.out |
3237 | out.project('project %s/', self.project.relpath) | 3242 | out.project('project %s/', self.project.RelPath(local=False)) |
3238 | out.nl() | 3243 | out.nl() |
3239 | try: | 3244 | try: |
3240 | self.action() | 3245 | self.action() |