Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testcase notes] #23: Pull request, different branches inside one repo, both commits, conflict #56

Open
dorawyy opened this issue Oct 22, 2017 · 1 comment

Comments

@dorawyy
Copy link
Owner

dorawyy commented Oct 22, 2017

PR2 branch was derived from PR1

Scenario abstract

--> Different branches inside one repo, both Alice and Bob commit (causing conflicts)

  • PR2 branch (Pull-Request-2 branch) was derived from PR1 branch (Pull-Request-1 branch)
  • Alice and Bob worked on the same repo, Alice(PR2 branch), Bob(PR1 branch)
  • Alice made commits on PR2 branch, fileX, line Y, locally
  • Alice git push origin PR2
  • Bob made commits on PR1 branch, fileX, line Y, locally
  • Bob git push origin PR1
  • Alice made a pull request to Bob: FROM: repo1, PR2 --> TO: repo1, PR1
  • What would Bob do and meet?
    • What if he merge directly
    • What if he squash commits then merge?
    • What if he rebase then merge?

Results:

  • Option1: When create a merge commit,

  • Option2: When squash commits and merge,

  • Option3: When rebase and merge,

Data could be explored:

  • Option1: When create a merge commit

  • Option2: When create a merge commit

  • Option3: When rebase and merge


Detailed steps:

Step0: prep

  • createtest23 as test file on PR1
  • create PR2 branch from PR1 branch
git checkout PR1
touch test23
vim test23
git add test23
git commit -m "testcase23: startpoint (create file test23 on PR1 branch)"
git push origin PR1

git checkout PR2
git merge PR1
git push origin PR2

##### Now both PR1 and PR2 are set, at the same commit, we can start the test case

Content of test23 :
screen shot 2017-10-22 at 12 35 28 am

Startpoint - project tree:
screen shot 2017-10-22 at 12 36 17 am


Step1: Alice committed on PR2 , test23, line14, pushed back to remote

git checkout PR2
vim test23
# edit test23, line 14

git add test23
git commit -m "PR2: edited the file test23, line 14"

git push origin PR2

The edit on the file test23 is:
screen shot 2017-10-22 at 12 36 59 am

After git push origin PR2, here is the project status:
screen shot 2017-10-22 at 12 37 33 am


Step2: Bob committed on PR1, test23, line14,(same line as Alice), pushed back to remote

git checkout PR1

# edit test23, line14

git add test23
git commit -m "PR1: edited the file test23"

git push origin PR1

The edit on the file test23 from PR1 is:
screen shot 2017-10-22 at 12 38 17 am

After git push origin PR1, the two branches diverge, here is the status of PR1:
screen shot 2017-10-22 at 12 38 57 am

Here is the status of the whole project:
screen shot 2017-10-22 at 12 39 11 am


Step3: Alice made a pull request to merge PR1(base) and PR2 (head)

This is the page that Alice will see when she create a new pull request:
screen shot 2017-10-22 at 12 39 48 am

Here are details of the pull request, created by Alice ( pull request: #59 ):
screen shot 2017-10-22 at 12 44 55 am
screen shot 2017-10-22 at 12 45 08 am
screen shot 2017-10-22 at 12 46 26 am

Note: merge conflict here


Step4: Alice work is done, now Bob's turn. He needs to decide what to do with the pull request.

Note: merge conflict here


Step5: Bob needs to resolve the conflict first

Bob can use web editor or command line to resolve the merge conflict;
screen shot 2017-10-22 at 12 48 24 am

In this test case, we simply use Web editor, might use command line in later test cases

Way1: web editor to resolve conflict

[open web editor]
screen shot 2017-10-22 at 12 48 00 am

[resolve conflict]
screen shot 2017-10-22 at 12 53 05 am

[merge back]
screen shot 2017-10-22 at 12 53 17 am

Now, come back to the pull request page

screen shot 2017-10-22 at 12 59 05 am

Note that option3: rebasing is disabled, which is because there is merge conflict before. If rebasing, will meet the same conflict again, which cannot be automatically resolved, Github then disabled that.

Git pull to local, check repo status

git checkout PR1
git pull origin PR1

git checkout PR2
git pull origin PR2

screen shot 2017-10-22 at 1 03 43 am 1

Commits history of PR2 (head branch)
screen shot 2017-10-22 at 1 06 42 am

Details of the merge commit:
screen shot 2017-10-22 at 1 07 36 am


Option1: Create a merge commit

All commits from this branch (PR2 in this case) will be added to the base branch via a merge commit.

Bob chose to merge pull request

screen shot 2017-10-22 at 1 17 27 am

Bob filled in info when merge pull request

screen shot 2017-10-22 at 1 18 45 am

Then the pull request is done
screen shot 2017-10-22 at 1 19 34 am

Check PR1 and PR2 commit history

History of PR1 branch:
screen shot 2017-10-22 at 1 26 01 am

History of PR2 branch (head repo, no change):
screen shot 2017-10-22 at 1 25 40 am

Observations:

  • PR1:

    • the commits on PR2 ( head branch) also applied here
    • a pull request merge commit is created
  • PR2:

    • no change, now behind PR1

Details of the merge commit is:

screen shot 2017-10-22 at 1 29 51 am

Pull PR1 and PR2 to local again, merge, then push back to remote

git checkout PR1
git pull origin PR1

screen shot 2017-10-22 at 1 31 50 am

git checkout PR2
git pull origin PR2
git merge PR1
git push origin PR2

The project status becomes:
screen shot 2017-10-22 at 1 33 14 am

@dorawyy
Copy link
Owner Author

dorawyy commented Oct 22, 2017

PR2 branch was derived from PR1

Option2

Scenario abstract

--> Different branches inside one repo, both Alice and Bob commit (causing conflicts)

  • PR2 branch (Pull-Request-2 branch) was derived from PR1 branch (Pull-Request-1 branch)
  • Alice and Bob worked on the same repo, Alice(PR2 branch), Bob(PR1 branch)
  • Alice made commits on PR2 branch, fileX, line Y, locally
  • Alice git push origin PR2
  • Bob made commits on PR1 branch, fileX, line Y, locally
  • Bob git push origin PR1
  • Alice made a pull request to Bob: FROM: repo1, PR2 --> TO: repo1, PR1
  • What would Bob do and meet?
    • What if he squash commits then merge?

Results:

  • Option2: When squash commits and merge,

Data could be explored:

  • Option2: When create a merge commit

Detailed steps:

Step0: prep

  • createtest23_option2 as test file on PR1
  • sync PR2 branch with PR1 branch
git checkout PR1
touch test23_option2
vim test23_option2g
git add test23_option2
git commit -m "testcase23_option2: startpoint (create file test23 on PR1 branch)"
git push origin PR1

git checkout PR2
git merge PR1
git push origin PR2

##### Now both PR1 and PR2 are set, at the same commit, we can start the test case

Content of testcase23_option2 :
screen shot 2017-10-22 at 1 50 16 am

Startpoint - project tree:
screen shot 2017-10-22 at 1 51 21 am


Step1: Alice committed on PR2 , test23_option2, line14, pushed back to remote

git checkout PR2
vim test23_option2
# edit test23_option2, line 14

git add test23_option2
git commit -m "PR2: edited the file test23_option2, line 14"

git push origin PR2

The edit on the file testcase23_option2 is:
screen shot 2017-10-22 at 1 52 10 am

After git push origin PR2, here is the project status:
screen shot 2017-10-22 at 1 53 24 am


Step2: Bob committed on PR1, test23_option2, line14,(same line as Alice), pushed back to remote

git checkout PR1

# edit test23_option2, line14

git add test23_option2
git commit -m "PR1: edited the file test23_option2"

git push origin PR1

The edit on the file testcase23_option2 from PR1 is:
screen shot 2017-10-22 at 1 54 53 am

After git push origin PR1, the two branches diverge, here is the status of PR1:
screen shot 2017-10-22 at 1 55 29 am

Here is the status of the whole project:
screen shot 2017-10-22 at 1 56 02 am


Step3: Alice made a pull request to merge PR1(base) and PR2 (head)

This is the page that Alice will see when she create a new pull request:
screen shot 2017-10-22 at 1 57 10 am

Here are details of the pull request, created by Alice ( pull request: #60 ):
screen shot 2017-10-22 at 1 59 30 am
screen shot 2017-10-22 at 1 59 46 am
screen shot 2017-10-22 at 1 59 55 am

Note: merge conflict here


Step4: Alice work is done, now Bob's turn. He needs to decide what to do with the pull request.

Note: merge conflict here


Step5: Bob needs to resolve the conflict first

Bob can use web editor or command line to resolve the merge conflict;

In this test case, we choose to use command line:

First, fetch all remote updates to local:

git checkout PR1
git pull origin PR1

git checkout PR2
git pull origin PR2

The project history becomes:
screen shot 2017-10-22 at 9 00 25 am

Way2: command line to resolve conflict

Bob, PR1, test23_option2:
screen shot 2017-10-22 at 9 02 26 am

Alice, PR2, test23_option2:
screen shot 2017-10-22 at 9 03 37 am

Nothing showed here. Go back to web editor and try resolve the conflict.

Way1: web editor to resolve conflict

screen shot 2017-10-22 at 9 05 11 am

[resolve conflict]
screen shot 2017-10-22 at 9 07 13 am

[merge back]
screen shot 2017-10-22 at 9 07 21 am

Now, come back to the pull request page
screen shot 2017-10-22 at 9 09 03 am

Note that option3: rebasing is disabled, which is because there is merge conflict before. If rebasing, will meet the same conflict again, which cannot be automatically resolved, Github then disabled that.
screen shot 2017-10-22 at 9 10 13 am

Git pull to local, check repo status

git checkout PR1
git pull origin PR1

git checkout PR2
git pull origin PR2

Uploading Screen Shot 2017-10-22 at 9.11.17 AM.png…

Commits history of PR2 (head branch)
screen shot 2017-10-22 at 9 12 45 am

Details of the merge commit:
screen shot 2017-10-22 at 9 13 29 am


Option2: Squash commits and merge

Bob chose to squash commits and merge

screen shot 2017-10-22 at 5 11 31 pm

Bob filled in info when squash commits and merge

screen shot 2017-10-22 at 5 14 23 pm

Then the pull request is done
screen shot 2017-10-22 at 5 15 31 pm

Check PR1 and PR2 commit history

History of PR1 branch: (a squash commit created)
(before squash commits)
screen shot 2017-10-22 at 5 15 08 pm
(after squash commits)
screen shot 2017-10-22 at 5 15 41 pm

History of PR2 branch (head repo, no change):
(before squash commits)
screen shot 2017-10-22 at 5 14 59 pm
(after squash commits)
screen shot 2017-10-22 at 5 15 54 pm

Observations:

  • PR1: (head branch)

    • a squash commit is created, however, it is a normal commit (with 1 parent)
  • PR2: (base branch)

    • no change

Details of the squash commit on the base branch is:
screen shot 2017-10-22 at 5 27 51 pm

Pull PR1 and PR2 to local again ( still diverge)

git checkout PR1
git pull origin PR1

screen shot 2017-10-22 at 5 33 36 pm

git checkout PR2
git pull origin PR2

screen shot 2017-10-22 at 5 34 27 pm

The project status becomes:
screen shot 2017-10-22 at 5 34 52 pm

Merge the two branches PR1 and PR2 locally

git checkout PR2
git merge PR1

git push origin PR2

( three-way merging with no conflict here)
screen shot 2017-10-22 at 5 36 17 pm

Now the project status becomes:
screen shot 2017-10-22 at 5 37 06 pm

git checkout PR1
git merge PR2
git push origin PR1

( fast-forward merging)
screen shot 2017-10-22 at 5 37 40 pm

The project status becomes (all in sync now):
screen shot 2017-10-22 at 5 39 28 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant