

def Execute(self, opt, args):
    if (len(args) != 1):
        self.Usage()
    reference = args[0]
    p = GitCommand(None, ['rev-parse', '--verify', reference], capture_stdout=True, capture_stderr=True)
    if (p.Wait() != 0):
        print(p.stderr, file=sys.stderr)
        sys.exit(1)
    sha1 = p.stdout.strip()
    p = GitCommand(None, ['cat-file', 'commit', sha1], capture_stdout=True)
    if (p.Wait() != 0):
        print('error: Failed to retrieve old commit message', file=sys.stderr)
        sys.exit(1)
    old_msg = self._StripHeader(p.stdout)
    p = GitCommand(None, ['cherry-pick', sha1], capture_stdout=True, capture_stderr=True)
    status = p.Wait()
    print(p.stdout, file=sys.stdout)
    print(p.stderr, file=sys.stderr)
    if (status == 0):
        new_msg = self._Reformat(old_msg, sha1)
        p = GitCommand(None, ['commit', '--amend', '-F', '-'], provide_stdin=True, capture_stdout=True, capture_stderr=True)
        p.stdin.write(new_msg)
        p.stdin.close()
        if (p.Wait() != 0):
            print('error: Failed to update commit message', file=sys.stderr)
            sys.exit(1)
    else:
        print('NOTE: When committing (please see above) and editing the commit message, please remove the old Change-Id-line and add:')
        print(self._GetReference(sha1), file=sys.stderr)
        print(file=sys.stderr)

dataset/ETHPy150Open esrlabs/git-repo/subcmds/cherry_pick.py CherryPick.Execute/original