⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 291716 in webkit


Ignore:
Timestamp:
Mar 22, 2022, 4:00:11 PM (5 years ago)
Author:
Jonathan Bedard
Message:

[git-webkit] Do not re-prompt configuration options during setup
​https://bugs.webkit.org/show_bug.cgi?id=237571
<rdar://problem/89940351>

Reviewed by Dewei Zhu.

  • Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
  • Tools/Scripts/libraries/webkitscmpy/webkitscmpy/init.py: Ditto.
  • Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py:

(Setup.git): Skip already configured options by default.
(Setup.parser): Add option to re-prompt for previously configured options.

  • Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py:

Canonical link: ​https://commits.webkit.org/248753@main

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r291627 r291716  
     12022-03-22  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [git-webkit] Do not re-prompt configuration options during setup
     4        https://bugs.webkit.org/show_bug.cgi?id=237571
     5        <rdar://problem/89940351>
     6
     7        Reviewed by Dewei Zhu.
     8
     9        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
     11        * Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py:
     12        (Setup.git): Skip already configured options by default.
     13        (Setup.parser): Add option to re-prompt for previously configured options.
     14        * Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py:
     15
    1162022-03-22  Jonathan Bedard  <jbedard@apple.com>
    217
  • trunk/Tools/Scripts/libraries/webkitscmpy/setup.py

    r291490 r291716  
    3030setup(
    3131    name='webkitscmpy',
    32     version='4.4.1',
     32    version='4.4.2',
    3333    description='Library designed to interact with git and svn repositories.',
    3434    long_description=readme(),
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py

    r291490 r291716  
    4747    )
    4848
    49 version = Version(4, 4, 1)
     49version = Version(4, 4, 2)
    5050
    5151AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py

    r291138 r291716  
    8181    @classmethod
    8282    def git(cls, args, repository, additional_setup=None, hooks=None, **kwargs):
     83        local_config = repository.config()
    8384        global_config = local.Git.config()
    8485        result = 0
    8586
    86         email = os.environ.get('EMAIL_ADDRESS') or global_config.get('user.email')
     87        email = os.environ.get('EMAIL_ADDRESS') or global_config.get('user.email') or local_config.get('user.email')
    8788        log.info('Setting git user email for {}...'.format(repository.root_path))
    88         if not email or args.defaults is False or (not args.defaults and Terminal.choose(
     89        if not email or args.defaults is False or (not args.defaults and args.all and Terminal.choose(
    8990            "Set '{}' as the git user email for this repository".format(email),
    9091            default='Yes',
    … …  
    9293            email = Terminal.input('Enter git user email for this repository: ')
    9394
    94         if run(
    95             [local.Git.executable(), 'config', 'user.email', email], capture_output=True, cwd=repository.root_path,
    96         ).returncode:
    97             sys.stderr.write('Failed to set the git user email to {} for this repository\n'.format(email))
    98             result += 1
    99         else:
    100             log.info("Set git user email to '{}' for this repository".format(email))
    101 
    102         name = repository.contributors.get(email)
    103         if name:
    104             name = name.name
    105         else:
    106             name = global_config.get('user.name')
     95        if email != local_config.get('user.email'):
     96            if run(
     97                [local.Git.executable(), 'config', 'user.email', email], capture_output=True, cwd=repository.root_path,
     98            ).returncode:
     99                sys.stderr.write('Failed to set the git user email to {} for this repository\n'.format(email))
     100                result += 1
     101            else:
     102                log.info("Set git user email to '{}' for this repository".format(email))
     103        else:
     104            log.info("Skipped setting email to '{}', it's already set for this repository".format(email))
     105
     106        contributor = repository.contributors.get(email)
     107        if contributor:
     108            name = contributor.name
     109        else:
     110            name = global_config.get('user.name') or local_config.get('user.name')
    107111        log.info('Setting git user name for {}...'.format(repository.root_path))
    108         if not name or args.defaults is False or (not args.defaults and Terminal.choose(
     112        if not name or args.defaults is False or (not args.defaults and args.all and Terminal.choose(
    109113            "Set '{}' as the git user name for this repository".format(name),
    110114            default='Yes',
    111115        ) == 'No'):
    112116            name = Terminal.input('Enter git user name for this repository: ')
    113         if run(
    114             [local.Git.executable(), 'config', 'user.name', name], capture_output=True, cwd=repository.root_path,
    115         ).returncode:
    116             sys.stderr.write('Failed to set the git user name to {} for this repository\n'.format(name))
    117             result += 1
    118         else:
    119             log.info("Set git user name to '{}' for this repository".format(name))
     117
     118        if name != local_config.get('user.name'):
     119            if run(
     120                [local.Git.executable(), 'config', 'user.name', name], capture_output=True, cwd=repository.root_path,
     121            ).returncode:
     122                sys.stderr.write('Failed to set the git user name to {} for this repository\n'.format(name))
     123                result += 1
     124            else:
     125                log.info("Set git user name to '{}' for this repository".format(name))
     126        else:
     127            log.info("Skipped setting name to '{}', it's already set for this repository".format(name))
    120128
    121129        if repository.metadata and os.path.isfile(os.path.join(repository.metadata, local.Git.GIT_CONFIG_EXTENSION)):
    … …  
    140148        log.info('Set better Objective-C diffing behavior for this repository!')
    141149
    142         if args.defaults or Terminal.choose(
     150        commands_to_color = ('color.status', 'color.diff', 'color.branch')
     151        need_prompt_color = args.all or any([not local_config.get(command) for command in commands_to_color])
     152        if args.defaults or (need_prompt_color and Terminal.choose(
    143153            'Auto-color status, diff, and branch for this repository?',
    144             default='Yes',
    145         ) == 'Yes':
    146             for command in ('status', 'diff', 'branch'):
    147                 result += run(
    148                     [local.Git.executable(), 'config', 'color.{}'.format(command), 'auto'],
    149                     capture_output=True, cwd=repository.root_path,
    150                 ).returncode
     154            default='Yes', options=('Yes', 'Skip'),
     155        ) == 'Yes'):
     156            for command in commands_to_color:
     157                if not local_config.get(command):
     158                    result += run(
     159                        [local.Git.executable(), 'config', command, 'auto'],
     160                        capture_output=True, cwd=repository.root_path,
     161                    ).returncode
    151162
    152163        if args.merge is None:
    … …  
    160171            result += 1
    161172
    162         if repository.config(location='project')['webkitscmpy.history'] == 'never':
    163             pr_history = 'never'
    164         elif repository.config(location='project')['webkitscmpy.pull-request'] != 'overwrite':
    165             pr_history = None
    166         elif args.defaults:
    167             pr_history = repository.config(location='project')['webkitscmpy.history']
    168         else:
    169             pr_history = Terminal.choose(
    170                 'Would you like to create new branches to retain history when you overwrite\na pull request branch?',
    171                 default=repository.config(location='project')['webkitscmpy.history'],
    172                 options=repository.PROJECT_CONFIG_OPTIONS['webkitscmpy.history'],
    173             )
    174         if pr_history and run(
    175             [local.Git.executable(), 'config', 'webkitscmpy.history', pr_history],
    176             capture_output=True, cwd=repository.root_path,
    177         ).returncode:
    178             sys.stderr.write("Failed to set '{}' as the default history management approach\n".format(pr_history))
    179             result += 1
     173        if args.all or not local_config.get('webkitscmpy.history'):
     174            if repository.config(location='project')['webkitscmpy.history'] == 'never':
     175                pr_history = 'never'
     176            elif repository.config(location='project')['webkitscmpy.pull-request'] != 'overwrite':
     177                pr_history = None
     178            elif args.defaults:
     179                pr_history = repository.config(location='project')['webkitscmpy.history']
     180            else:
     181                pr_history = Terminal.choose(
     182                    'Would you like to create new branches to retain history when you overwrite\na pull request branch?',
     183                    default=repository.config(location='project')['webkitscmpy.history'],
     184                    options=repository.PROJECT_CONFIG_OPTIONS['webkitscmpy.history'],
     185                )
     186            if pr_history and run(
     187                [local.Git.executable(), 'config', 'webkitscmpy.history', pr_history],
     188                capture_output=True, cwd=repository.root_path,
     189            ).returncode:
     190                sys.stderr.write("Failed to set '{}' as the default history management approach\n".format(pr_history))
     191                result += 1
    180192
    181193        if hooks:
    … …  
    201213                os.chmod(target, 0o775)
    202214
    203         log.info('Setting git editor for {}...'.format(repository.root_path))
    204         editor_name = 'default' if args.defaults else Terminal.choose(
    205             'Pick a commit message editor for this repository',
    206             options=['default'] + [program.name for program in Editor.programs()],
    207             default='default',
    208             numbered=True,
    209         )
    210         if editor_name == 'default':
    211             log.info('Using the default git editor for this repository')
    212         elif run(
    213             [local.Git.executable(), 'config', 'core.editor', ' '.join([arg.replace(' ', '\\ ') for arg in Editor.by_name(editor_name).wait])],
    214             capture_output=True,
    215             cwd=repository.root_path,
    216         ).returncode:
    217             sys.stderr.write('Failed to set the git editor to {} for this repository\n'.format(editor_name))
    218             result += 1
    219         else:
    220             log.info("Set git editor to '{}' for this repository".format(editor_name))
     215        if args.all or not local_config.get('core.editor'):
     216            log.info('Setting git editor for {}...'.format(repository.root_path))
     217            editor_name = 'default' if args.defaults else Terminal.choose(
     218                'Pick a commit message editor for this repository',
     219                options=['default'] + [program.name for program in Editor.programs()],
     220                default='default',
     221                numbered=True,
     222            )
     223            if editor_name == 'default':
     224                log.info('Using the default git editor for this repository')
     225            elif run(
     226                [local.Git.executable(), 'config', 'core.editor', ' '.join([arg.replace(' ', '\\ ') for arg in Editor.by_name(editor_name).wait])],
     227                capture_output=True,
     228                cwd=repository.root_path,
     229            ).returncode:
     230                sys.stderr.write('Failed to set the git editor to {} for this repository\n'.format(editor_name))
     231                result += 1
     232            else:
     233                log.info("Set git editor to '{}' for this repository".format(editor_name))
    221234
    222235        # Pushing to http repositories is difficult, offer to change http checkouts to ssh
    … …  
    299312            help='Use a merge-commit workflow instead of a rebase workflow',
    300313        )
     314        parser.add_argument(
     315            '--all', '-a', action='store_true', default=False,
     316            help='Prompt the user for all options, do not assume responses from the current configuration',
     317        )
    301318
    302319    @classmethod
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/setup_unittest.py

    r290661 r291716  
    6969
    7070    def test_git(self):
     71        self.maxDiff = None
    7172        with OutputCapture(level=logging.INFO) as captured, mocks.local.Git(self.path) as repo, \
    7273            mocks.local.Svn(), wkmocks.Environment(EMAIL_ADDRESS=''):
    … …  
    9596            captured.root.log.getvalue(),
    9697            '''Setting git user email for {repository}...
    97 Set git user email to 'tapple@webkit.org' for this repository
     98Skipped setting email to 'tapple@webkit.org', it's already set for this repository
    9899Setting git user name for {repository}...
    99 Set git user name to 'Tim Apple' for this repository
     100Skipped setting name to 'Tim Apple', it's already set for this repository
    100101No project git config found, continuing
    101102Setting better Objective-C diffing behavior for this repository...
    … …  
    110111        self.maxDiff = None
    111112        with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, \
    112             MockTerminal.input('n', 'n', 'committer@webkit.org', 'n', 'Committer', 'n', 'overwrite', 'disabled', '1', 'y', 'y'), \
     113            MockTerminal.input('n', 'n', 'committer@webkit.org', 'n', 'Committer', 's', 'overwrite', 'disabled', '1', 'y', 'y'), \
    113114            mocks.local.Git(self.path, remote='https://{}.git'.format(remote.remote)) as repo, \
    114115            wkmocks.Environment(EMAIL_ADDRESS=''):
    … …  
    117118
    118119            self.assertEqual(0, program.main(
    119                 args=('setup', '-v'),
     120                args=('setup', '-v', '-a'),
    120121                path=self.path,
    121122            ))
    … …  
    139140Set 'Tim Apple' as the git user name for this repository ([Yes]/No):
    140141Enter git user name for this repository:
    141 Auto-color status, diff, and branch for this repository? ([Yes]/No):
     142Auto-color status, diff, and branch for this repository? ([Yes]/Skip):
    142143Would you like to create new branches to retain history when you overwrite
    143144a pull request branch? ([when-user-owned]/disabled/always/never):
Note: See TracChangeset for help on using the changeset viewer.