User Tools

Site Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
github_best_practices [2018/08/31 23:29] – [After Successful Test] Traumfluggithub_best_practices [2019/10/05 14:00] (current) – [File Permissions] Clarify link. Traumflug
Line 11: Line 11:
  
   * [[https://git-scm.com/|Git]]. Obviously. Ubuntu came with version 2.17.1 when this page was created.   * [[https://git-scm.com/|Git]]. Obviously. Ubuntu came with version 2.17.1 when this page was created.
-  * [[https://git-scm.com/docs/gitk|Gitk]]. Part of the official Git distribution. A simple and efficient repository browser giving a good overview. Without this overview it's often hard to understand what's going on. Command line parameters don't matter, one starts it with ''gitk --all&'' (two dashes) in the repository to browse.+  * [[https://git-scm.com/docs/gitk|Gitk]]. Part of the official Git distribution. A simple and efficient repository browser giving a good overview. Without this overview it's often hard to understand what's going on. Command line parameters don't matter, one starts it with ''gitk --all&'' in the repository to browse.
  
 +For refreshing the repository view in Gitk, menu -> //File// -> //Update// (F5) is often incomplete. Menu -> //File// -> //Reload// (Shift-F5) is the much better choice.
  
 +
 +===== Merging is Evil =====
 +
 +{{ :developers:messy_git_history.png?direct|Which code changes led to release 1.6.1.2-RC3 and which branch should be taken when searching backwards in history for finding a regression?}}
 +Ouch? Well, let's refine the sentence: "Non-fast-forward merges are evil".
 +
 +Believe it or not, I use Git since it's early days, use it many times a day, and I //never// merged anything. It felt wrong from the beginning and today, quite some experience joined this feeling.
 +
 +The simple reason can be seen on the right: extensive use of merges creates an messy history and having nothing but a mess makes having a history almost pointless.
 +
 +Maintaining a linear history isn't too hard:
 +
 +  * Use [[https://git-scm.com/docs/git-rebase|git rebase]].
 +  * Use [[https://git-scm.com/docs/git-cherry-pick|git cherry-pick]].
 +  * Use [[https://git-scm.com/docs/git-merge#git-merge---ff-only|git merge]] only with the ''--ff-only'' option.
 +
 +A number of expert tasks, e.g. interactive rebasing or filtering, works on linear histories, only. Git simply flattens the history in such cases, which not only removes most commit messages, it can also cause a lot of conflicts.
 ===== Avoid broken Code on the Main Branch ===== ===== Avoid broken Code on the Main Branch =====
  
 We all make mistakes. Typos, incompatibilities with other PHP versions, such stuff. That's why thirty bees core repository invokes Travis CI on every branch tip pushed to the repository. We all make mistakes. Typos, incompatibilities with other PHP versions, such stuff. That's why thirty bees core repository invokes Travis CI on every branch tip pushed to the repository.
  
-However, such code shouldn't land on one of the main branches. Because it makes crawling or bisecting the history of the repository much harder. It also risks picking up the failure again when cherry-picking this particular commit to another branch. On main branches, every single commit should work flawlessly. Which isn't hard to achieve when following strategies here.+However, flawed code shouldn't land on one of the main branches. Because it makes crawling or bisecting the history of the repository much harder. It also risks picking up the failure again when cherry-picking this particular commit to another branch. On main branches, every single commit should work flawlessly. Which isn't hard to achieve when following strategies here.
  
 A "topic branch" is any branch in a Git repository not being the main branch. This is, any branch other than //1.0.x// and //1.1.x// as of this writing. Topic branches can get created and removed as needed. A "topic branch" is any branch in a Git repository not being the main branch. This is, any branch other than //1.0.x// and //1.1.x// as of this writing. Topic branches can get created and removed as needed.
Line 26: Line 44:
 The most simple way to avoid broken code entering main branches is to test on topic branches. Put your commits there, then push them. Such branches get tested the exactly same way as the main branch. What works on a topic branch works on the main branch as well. The most simple way to avoid broken code entering main branches is to test on topic branches. Put your commits there, then push them. Such branches get tested the exactly same way as the main branch. What works on a topic branch works on the main branch as well.
  
-As one can see, I simply use a topic branch //markus// for everyday work:+As one can see, I simply use a topic branch named //markus// for everyday work:
  
 {{ :developers:topic_branch_created.png?direct |Topic branch created.}} {{ :developers:topic_branch_created.png?direct |Topic branch created.}}
Line 40: Line 58:
 ==== After Successful Test ==== ==== After Successful Test ====
  
-After Travis CI tested found no flaws, main branch gets forwarded to the topic branch:+If Travis CI tests found no flaws, the main branch gets forwarded to the topic branch:
 <code none> <code none>
 git checkout 1.0.x git checkout 1.0.x
Line 55: Line 73:
 Tip of branch //1.0.x// is now the exactly same as the tip of branch //markus//, they share the same Git hash. Due to a [[https://github.com/travis-ci/travis-ci/issues/2200|flaw in Travis CI]] it'll get tested again, which doesn't matter. Result of the second run will be the same as that of the first one. Tip of branch //1.0.x// is now the exactly same as the tip of branch //markus//, they share the same Git hash. Due to a [[https://github.com/travis-ci/travis-ci/issues/2200|flaw in Travis CI]] it'll get tested again, which doesn't matter. Result of the second run will be the same as that of the first one.
  
-Task done. Don't forget to switch back to the topic branch before picking up the next task:+Task done. Don't forget to switch back to the topic branch before picking up on the next task:
 <code none> <code none>
 git checkout markus git checkout markus
 </code> </code>
 +
 +==== On Test Failure ====
 +
 +Test failures are no big deal as long as they happen on a topic branch. Now two things should happen:
 +
 +  * Fix the flaw on the topic branch.
 +  * Edit commit(s) in place.
 +
 +The latter is essential, else the broken commit will stay broken, with all the drawbacks described above.
 +
 +=== Editing the Last Commit ===
 +
 +Editing a commit in place is trivial in case it's the last commit. One does code fixes as usual, then commit the same way as when creating a new commit, but add the ''--amend'' parameter. Like:
 +<code none>
 +git commit --amend
 +</code>
 +This brings up the commit editor as usual, one proceeds as usual.
 +
 +With this done, the repository looks like this:
 +
 +{{ :developers:topic_branch_after_amend.png?direct |Topic branch after amending a commit.}}
 +
 +Local and remote Git hashes are no longer the same. To nevertheless push this branch, one needs the additional ''-f'' flag:
 +<code none>
 +git push -f thirtybees markus
 +</code>
 +That's all. Travis CI will run again on this branch. Depending on test results, repeat this section until tests succeed, or continue in section [[#After Successful Test]].
 +
 +=== Editing an Earlier Commit ===
 +
 +Editing a commit which is not the last one requires interactive rebasing. That's a bit more complicated and also a very powerful tool. To stress this wiki page not too much, here are some good tutorials:
 +
 +  * [[https://dev.to/blakedeboer/beginners-guide-to-interactive-rebasing-1ob|Blake DeBoer on interactive rebasing]]
 +  * [[https://robots.thoughtbot.com/git-interactive-rebase-squash-amend-rewriting-history|Tute Costa on interactive rebasing]]
 +  * [[https://hackernoon.com/beginners-guide-to-interactive-rebasing-346a3f9c3a6d|Hacker Noon on interactive rebasing]]
 +  * [[https://www.youtube.com/watch?v=tukOm3Afd8s|Video tutorial on interactive rebasing]]
 +
 +Remember, your topic branch is __yours__, so no fear in rewriting history.
 +===== Picking Pull Requests =====
 +
 +It's as simple as clicking the //Merge pull request// button on the Github web page, right? Wrong.
 +
 +This button has flaws:
 +
 +  * No review possible. Well, one can stare at the commit, of course, but not edit or test it.
 +  * Potential to write a nonlinear history. Drawbacks see [[#Merging is Evil]] above.
 +  * Pointless work for those creating the pull request. A simple link to a commit in another repository works just as well.
 +
 +One can easily ignore this button. Picking pull requests, or any commit on Github, is pretty trivial:
 +
 +  - Find the commit on Github. It's an URL like ''github.com/thirtybees/thirtybees/pull/31/commits/<git hash>''.
 +  - Append ''.patch'' to this URL: ''.../commits/<git hash>.patch''
 +  - In your local repository clone, proceed like this:
 +<code none>
 +curl -L <URL> | git am -3
 +</code>
 +That's it! After this simple oneliner, one has this commit on top of the local branch, including author info and commit timestamp. Now one can review this commit, run the local shop installation with it, add remarks in the commit message, push it on a topic branch for a Travis CI run, and so on. Easy, and much more reliable.
 +
 +===== Dealing with Github Issues =====
 +
 +Here are some hints on good practices when dealing with Github issues.
 +
 +== Issue reports are of value ==
 +As unfortunate as it is, code has inevitably flaws. Now think of a given set of code, and the same set of code, together with a description of its flaws. The latter is undoubtly of more value.
 +
 +The only situation even better than code together with a description of its flaws is code with these flaws actually fixed.
 +
 +== Steps to reproduce ==
 +Good Github issues come with a list of steps to reproduce. Like:
 +
 +  - Have a fresh shop installation.
 +  - Install this.
 +  - Change this setting to that.
 +  - Expected behavior: [...]
 +  - Actual behavior: [...]
 +  - Screenshot, showing the flaw.
 +
 +First thing when attempting to fix a flaw is to reproduce the issue. If there is no list of steps to reproduce the bug, add it in a comment. This way everybody participating knows what's going on. If the issue appears to be not reproducible, for the lack of a description or the lack of a bug or because it was fixed already, ask the issue reporter.
 +
 +== Talk ==
 +If an issue can get fixed immediately, great! If not, it's a good idea to add comments about partial successes. Or things which were tried, but didn't work out.
 +
 +== Issue reporters close issues ==
 +Many projects have the habit to close issue reports quickly. Sometimes by writing some magic words into the commit message.
 +
 +Closing a Github issue doesn't make the issue in code going away. As the issue reporter knows best whether something was actually fixed, it's a good idea to ask him and let him decide whether the issue is actually solved. Reports just waiting for an answer of the reporter don't hurt.
 +
 +== Issues get reported for a reason ==
 +One can often see issues getting closed within minutes with //'works as expected'//, especially in popular, matured projects.
 +
 +It's a good idea to keep in mind that people usually don't write issue reports because they're bored. They do have an issue. Maybe the user interface isn't intuitive. Maybe software behavior can get improved. Getting such seemingly wrong reports is often a sign there's some room for improvement. This should be leveraged. thirty bees should be easy and intuitive to use, even for newbies.
 +
 +
 +===== This and That =====
 +
 +A couple of smaller tasks, in loose order.
 +
 +==== Recovery From a Failed Stash Pop ====
 +
 +In some situations a ''git stash pop'' or a command using the ''--autostash''  parameter doesn't restore the repository to its previous state. Instead it mumbles something about //"need merge"// or something.
 +
 +Knowing the secret, recovery is simple:
 +<code none>
 +git stash drop
 +git reset .
 +</code>
 +
 +==== File Permissions ====
 +
 +A typical problem of developer installations is trouble with file permissions. While the Git repository is owned by the developer, the web server runs as another user. Result: developer can't edit files created by the web server and vice versa.
 +
 +Solution is to use extended file permissions. First, move //.git// aside:
 +
 +  $ mv <git repository>/.git /tmp
 +
 +Then follow instructions at [[Developer Installation#The User Privileges Issue|Developer Installation]].
 +
 +That done, move //.git// back:
 +
 +  $ mv /tmp/.git <git repository>/
  
 ===== References ===== ===== References =====
github_best_practices.1535750968.txt.gz · Last modified: 2018/08/31 23:29 by Traumflug