Is my fork up to date?

Before you start work, compare your fork with the original project. Each commit has a short hash; compare the two histories.

What to build

A program that compares the commits of upstream and a fork and says how to sync.

Requirements

  • Line 1 has the commit hashes of upstream, oldest first, separated by spaces (it may be empty). Line 2 has the commits of the fork in the same way.
  • Print behind: HASHES, the upstream commits that the fork lacks, in upstream order and separated by a comma and a space, or behind: none.
  • Print ahead: HASHES, the fork commits that upstream lacks, in fork order, or ahead: none.
  • Print action: up to date if both are none. If only behind has commits print action: fast-forward. If only ahead has commits print action: ready for a pull request. If both have commits print action: rebase needed.

Input

Two lines of space-separated hashes.

Output

Three lines.

Constraints

Each line has at most 50 hashes of up to 10 letters or digits.

Example

Input:

a1 b2 c3 d4
a1 b2

Output:

behind: c3, d4
ahead: none
action: fast-forward

Why it works

The two differences are just two filtered lists, and the action follows from which are empty: no own commits means the branch can be moved forward, and no missing commits means there is nothing to bring in, so the changes can be proposed.

Examples

Example 1 · Input
a1 b2 c3 d4
a1 b2
Expected output
behind: c3, d4
ahead: none
action: fast-forward
Example 2 · Input
a1 b2
a1 b2 x9
Expected output
behind: none
ahead: x9
action: ready for a pull request

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Use the other list for membership: [h for h in upstream if h not in fork].

Hint 2

Both lines may be empty, so use split() without arguments.

Hint 3

Decide the action by which of the two lists is empty.

Solution

Show one correct solution (try it yourself first)
upstream = input().split()
fork = input().split()
behind = [h for h in upstream if h not in fork]
ahead = [h for h in fork if h not in upstream]
print("behind: " + (", ".join(behind) if behind else "none"))
print("ahead: " + (", ".join(ahead) if ahead else "none"))
if not behind and not ahead:
    print("action: up to date")
elif not ahead:
    print("action: fast-forward")
elif not behind:
    print("action: ready for a pull request")
else:
    print("action: rebase needed")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Your first contribution →