def test_submit_create(in_process, git_repo_path, init_sha):
    call_conduit.side_effect = (dict(), dict(data=[dict(phid='PHID-REPO-1', fields=dict(vcs='git'))]), [dict(userName='alice', phid='PHID-USER-1')], dict(dict(phid='PHID-DIFF-1', diffid='1')), dict(), dict(object=dict(id='123')), dict())
    (git_repo_path / 'X').write_text(u'ą\nb\nc\n', encoding='utf-8')
    (git_repo_path / 'Y').write_text('no line ending')
    git_out('add', '.')
    (git_repo_path / 'msg').write_text(u'Ą r?alice', encoding='utf-8')
    git_out('commit', '--file', 'msg')
    (git_repo_path / 'untracked').write_text('a\n')
    mozphab.main(['submit', '--yes', '--bug', '1', init_sha], is_development=True)
    log = git_out('log', '--format=%s%n%n%b', '-1')
    expected = '\nBug 1 - Ą r?alice\n\nDifferential Revision: http://example.test/D123\n\n'
    assert (log.strip() == expected.strip())
    assert (mock.call('conduit.ping', {}) in call_conduit.call_args_list)
    assert (mock.call('user.query', dict(usernames=['alice'])) in call_conduit.call_args_list)
    assert (mock.call('diffusion.repository.search', dict(limit=1, constraints=dict(callsigns=['TEST']))) in call_conduit.call_args_list)
    assert (mock.call('differential.creatediff', {'sourceControlPath': '/', 'sourceControlSystem': 'git', 'lintStatus': 'none', 'sourcePath': mock.ANY, 'unitStatus': 'none', 'sourceMachine': 'http://example.test', 'sourceControlBaseRevision': mock.ANY, 'repositoryPHID': 'PHID-REPO-1', 'branch': 'HEAD', 'changes': [{'commitHash': mock.ANY, 'awayPaths': [], 'newProperties': {'unix:filemode': '100644'}, 'oldPath': None, 'hunks': [{'oldOffset': 0, 'oldLength': 0, 'newOffset': 1, 'newLength': 3, 'addLines': 3, 'delLines': 0, 'corpus': '+ą\n+b\n+c\n', 'isMissingOldNewline': False, 'isMissingNewNewline': False}], 'oldProperties': {}, 'currentPath': 'X', 'fileType': 1, 'type': 1, 'metadata': {}}, {'commitHash': mock.ANY, 'awayPaths': [], 'newProperties': {'unix:filemode': '100644'}, 'oldPath': None, 'hunks': [{'oldOffset': 0, 'oldLength': 0, 'newOffset': 1, 'newLength': 1, 'addLines': 1, 'delLines': 0, 'corpus': '+no line ending\n\\ No newline at end of file\n', 'isMissingOldNewline': False, 'isMissingNewNewline': True}], 'oldProperties': {}, 'currentPath': 'Y', 'fileType': 1, 'type': 1, 'metadata': {}}], 'creationMethod': 'moz-phab-git'}) in call_conduit.call_args_list)
    assert (mock.call('differential.setdiffproperty', {'diff_id': '1', 'name': 'local:commits', 'data': (~ Contains('"rev":'))}) in call_conduit.call_args_list)
    assert (call_conduit.call_args_list.count(mock.call('differential.setdiffproperty', mock.ANY)) == 2)
def test_submit_create(in_process, git_repo_path, init_sha):
    call_conduit.side_effect = (dict(), dict(data=[dict(phid='PHID-REPO-1', fields=dict(vcs='git'))]), [dict(userName='alice', phid='PHID-USER-1')], dict(dict(phid='PHID-DIFF-1', diffid='1')), dict(), dict(object=dict(id='123')), dict())
    (git_repo_path / 'X').write_text(u'ą\nb\nc\n', encoding='utf-8')
    (git_repo_path / 'Y').write_text('no line ending')
    git_out('add', '.')
    (git_repo_path / 'msg').write_text(u'Ą r?alice', encoding='utf-8')
    git_out('commit', '--file', 'msg')
    (git_repo_path / 'untracked').write_text('a\n')
    mozphab.main(['submit', '--yes', '--bug', '1', init_sha], is_development=True)
    log = git_out('log', '--format=%s%n%n%b', '-1')
    expected = '\nBug 1 - Ą r?alice\n\nDifferential Revision: http://example.test/D123\n\n'
    assert (log.strip() == expected.strip())
    assert (mock.call('conduit.ping', {}) in call_conduit.call_args_list)
    assert (mock.call('user.query', dict(usernames=['alice'])) in call_conduit.call_args_list)
    assert (mock.call('diffusion.repository.search', dict(limit=1, constraints=dict(callsigns=['TEST']))) in call_conduit.call_args_list)
    assert (mock.call('differential.creatediff', {'sourceControlPath': '/', 'sourceControlSystem': 'git', 'lintStatus': 'none', 'sourcePath': mock.ANY, 'unitStatus': 'none', 'sourceMachine': 'http://example.test', 'sourceControlBaseRevision': mock.ANY, 'repositoryPHID': 'PHID-REPO-1', 'branch': 'HEAD', 'changes': [{'commitHash': mock.ANY, 'awayPaths': [], 'newProperties': {'unix:filemode': '100644'}, 'oldPath': None, 'hunks': [{'oldOffset': 0, 'oldLength': 0, 'newOffset': 1, 'newLength': 3, 'addLines': 3, 'delLines': 0, 'corpus': '+ą\n+b\n+c\n', 'isMissingOldNewline': False, 'isMissingNewNewline': False}], 'oldProperties': {}, 'currentPath': 'X', 'fileType': 1, 'type': 1, 'metadata': {}}, {'commitHash': mock.ANY, 'awayPaths': [], 'newProperties': {'unix:filemode': '100644'}, 'oldPath': None, 'hunks': [{'oldOffset': 0, 'oldLength': 0, 'newOffset': 1, 'newLength': 1, 'addLines': 1, 'delLines': 0, 'corpus': '+no line ending\n\\ No newline at end of file\n', 'isMissingOldNewline': False, 'isMissingNewNewline': True}], 'oldProperties': {}, 'currentPath': 'Y', 'fileType': 1, 'type': 1, 'metadata': {}}], 'creationMethod': 'moz-phab-git'}) in call_conduit.call_args_list)
    assert (mock.call('differential.setdiffproperty', {'diff_id': '1', 'name': 'local:commits', 'data': (~ Contains('"rev":'))}) in call_conduit.call_args_list)
    assert (call_conduit.call_args_list.count(mock.call('differential.setdiffproperty', mock.ANY)) == 2)