#
# Copyright (c) 2016 Hewlett Packard Enterprise Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
- desc: |
    Test that default behaviour and options work

    Repository layout being checked (assumed already replayed)

          C---D               local/master
         /
    A---B---E---F             upstream/master

  tree:
    - [A, []]
    - [B, [A]]
    - [C, [B]]
    - [D, [C]]
    - [E, [B]]
    - [F, [E]]

  branches:
    head: [master, D]
    upstream: [upstream/master, F]

  parser-args: [import, upstream/master]

  pre-script: |
    import os

    from git.repo import Repo


    repo = Repo(os.path.curdir)
    repo.git.checkout("master")

    conflict_file = repo.git.diff("upstream/master~1..upstream/master",
                                  name_only=True)
    with open(conflict_file, "w") as f:
        f.write("hello world")

    repo.git.add(conflict_file)
    repo.git.commit(amend=True, no_edit=True)

  post-script: |
    import os

    from git.repo import Repo


    repo = Repo(os.path.curdir)

    conflict_file = repo.git.diff("upstream/master~1..upstream/master",
                                  name_only=True)
    repo.git.checkout("--ours", "--", conflict_file)
    repo.git.add(conflict_file)
    os.environ["GIT_EDITOR"] = "echo"
    repo.git.rebase("--continue")

