summaryrefslogtreecommitdiff
path: root/doc/README.git
blob: dde64bfb2c52e83b783952ceada50cd40ec280af (plain)
  1. ==========================================
  2. Distributed LedgerSMB Development With Git
  3. ==========================================
  4. This document demonstrates how developer-integrators can work on
  5. local LedgerSMB customization and help with upstream LedgerSMB
  6. development using the distributed version control system, git.
  7. git is useful in the following areas:
  8. * Help with upstream development of LedgerSMB
  9. * Make it easier to communicate send and receive bugfixes in
  10. prerelease/development versions of LedgerSMB
  11. * Making necessary customizations that are unsuitable for
  12. upstream LedgerSMB
  13. * Putting customer templates and graphics under version control
  14. * Layering multiple customization branches to reproduce a
  15. configuration required for a particular customer deployment
  16. * (One way of) putting the plaintext backup of the company
  17. database under version control. At any time you can and do
  18. make snapshots, then examine the diff to see how each
  19. LedgerSMB operation affects the database tables.
  20. Cloning the LedgerSMB Sourceforge Subversion Repository
  21. =======================================================
  22. In time we may have an official git mirror from which to clone
  23. (a very quick copy operation), but you can make your own clone
  24. of the LedgerSMB repository directly from Sourceforge:
  25. $ git svn -s clone https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/ ledgersmb
  26. Initialized empty Git repository in /path/to/ledgersmb/.git/
  27. A ledger-smb/login.pl
  28. A ledger-smb/menu.ini
  29. A ledger-smb/ledger-smb.gif
  30. A ledger-smb/is.pl
  31. A ledger-smb/VERSION
  32. (..., ..., go get coffee)
  33. An alternative method using rsync to bring down the entire
  34. subversion repository (not just the working copy) can be used
  35. for those experiencing sourceforge connection problems:
  36. $ rsync -avz rsync://ledger-smb.svn.sourceforge.net/svn/ledger-smb/* /path/to/ledger-smb.svn
  37. Then clone from that local subversion repository URL, rewriting
  38. the root to match the SourceForge repository:
  39. $ git svn clone --rewrite-root=https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/ file://path/to/ledger-smb.svn ledgersmb
  40. Fixing A Bug Using Git And Bugfix Branch
  41. ========================================
  42. This section demonstrates fixing a trivial bug in LedgerSMB. The
  43. method of communicating the patch to fix the bug differs
  44. depending on whether you have commit priviledges to the
  45. SourceForge repository or are using the SourceForge bug tracker
  46. to send a patch.
  47. Example: SourceForge Bug SF2046815
  48. ----------------------------------
  49. (Note: The following commit was actually made by einhverfr)
  50. During testing of LedgerSMB trunk, we found a simple bug in the
  51. schema definition, and filed the report as SF2046815:
  52. ERROR: column e.control_code does not exist LINE 1:
  53. ..._ap_account_id, ec.cash_account_id, ec.threshold,
  54. e.control_... ^ QUERY: SELECT c.id, e.id, ec.entity_class,
  55. ec.discount, ec.taxincluded, ec.creditlimit, ec.terms,
  56. ec.meta_number, ec.business_id, ec.language_code,
  57. ec.pricegroup_id, ec.curr, ec.startdate, ec.enddate,
  58. ec.ar_ap_account_id, ec.cash_account_id, ec.threshold,
  59. e.control_code, ec.id FROM company c JOIN entity e
  60. ON (c.entity_id = e.id) JOIN entity_credit_account ec
  61. ON (c.entity_id = ec.entity_id) WHERE e.id = $1 AND
  62. ec.entity_class = CASE WHEN $2 = 3 THEN 2 WHEN $2 IS NULL THEN
  63. ec.entity_class ELSE $2 END CONTEXT: PL/pgSQL
  64. function "entity__list_credit" line 4 at FOR over SELECT rows
  65. This is a one-liner fix, but it is still worth it to make a
  66. branch, since fast branching and easy merging are strengths of
  67. git. The practice scales up well when you want to maintain
  68. multiple branches and share them with others.
  69. For those new to git: Here, we have the prompt set up to display
  70. the current branch in parentheses. If git is not currently on
  71. any branch, the SHA1 name of the current HEAD will be displayed:
  72. We intend our bugfix branch to be against the current trunk, so
  73. we check that remote branch out. It is important to use the
  74. git-svn managed remotes only for branching purposes, never
  75. commit to them.
  76. (1.2_jfkw) $ git checkout trunk
  77. Note: moving to "trunk" which isn't a local branch
  78. If you want to create a new branch from this checkout, you may do so
  79. (now or later) by using -b with the checkout command again. Example:
  80. git checkout -b <new_branch_name>
  81. HEAD is now at cb92467... Adding meta_number to company_billing_info return set
  82. Update the branch to the latest revision before branching:
  83. (cb92467...) $ git svn rebase --all
  84. Current branch HEAD is up to date.
  85. Now, we'll make a bugfix-branch, I prefer it to be named after
  86. the SF bug:
  87. (cb92467...) $ git checkout -b 1.3_SF2046815_missing_entity_control_code
  88. Switched to a new branch "1.3_SF2046815_missing_entity_control_code"
  89. You can use the git branch command to list all local branches.
  90. For example, I'm keeping around all branches for bugs and
  91. features I've worked on:
  92. $ git branch
  93. 1.2_SF1877860_typo
  94. 1.2_SF1928336_renames
  95. 1.2_SF2013331_cookie_name
  96. 1.2_SF2025931_till_equals_1
  97. 1.2_cdog
  98. 1.2_cdog_templates
  99. 1.2_generate_salesorders_detail_default
  100. 1.2_jfkw
  101. 1.2_partnumber_like_space_delimiter
  102. 1.2_print_pdf_default
  103. 1.2_project_generate_orders
  104. 1.2_receipts_on_invoice_screen
  105. 1.2_require_customernumber
  106. 1.2_require_customernumber_set_to_name
  107. 1.2_sql_ins_customer_ins_project
  108. 1.3_SF2013331_cookie_name
  109. 1.3_SF2017284_smallgray_css
  110. 1.3_SF2043569_install_doc
  111. * 1.3_SF2046815_missing_entity_control_code
  112. 1.3_jfkw
  113. master
  114. Again, note that the remote branches (trunk, 1.2) are seen with
  115. the git branch -a command. You should never modify those, just
  116. think of them as read-only. Git will keep track of the remote
  117. origin branch your local branch came from.
  118. Back to the bugfixing task at hand. Edit the offending file:
  119. (1.3_SF2046815_missing_entity_control_code) $ emacsclient -n sql/Pg-database.sql
  120. And in your editor, fix, save, test, etc. When ready, view a
  121. diff of the branch tip (HEAD) to your working copy:
  122. (1.3_SF2046815_missing_entity_control_code) $ git diff
  123. diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql
  124. index e1d8251..5bf84c3 100644
  125. --- a/sql/Pg-database.sql
  126. +++ b/sql/Pg-database.sql
  127. @@ -19,6 +19,7 @@ CREATE index entity_class_idx ON entity_class(lower(class));
  128. CREATE TABLE entity (
  129. id serial UNIQUE,
  130. + control_code text not null,
  131. name text check (name ~ '[[:alnum:]_]'),
  132. entity_class integer references entity_class(id) not null ,
  133. created date not null default current_date,
  134. At this point you encounter something unique about git. You
  135. have an intermediary layer between your working copy and HEAD,
  136. called the index. The index has been described variously as
  137. 'the next commit'.
  138. Use the git status command to see what has changed in your
  139. working copy:
  140. (1.3_SF2046815_missing_entity_control_code) $ git status
  141. # On branch 1.3_SF2046815_missing_entity_control_code
  142. # Changed but not updated:
  143. # (use "git add <file>..." to update what will be committed)
  144. #
  145. # modified: sql/Pg-database.sql
  146. #
  147. no changes added to commit (use "git add" and/or "git commit -a")
  148. And decide which files among these, in whole or just in part
  149. should be added to the index, which is to be the next commit.
  150. In this case, there's only one file changed, so you can add it
  151. to the next local commit by filename, or by adding all under the
  152. current directory (e.g. '.'):
  153. (1.3_SF2046815_missing_entity_control_code) $ git add .
  154. Check the status now, where you see that file added to the index
  155. is designated 'to be committed'.
  156. (1.3_SF2046815_missing_entity_control_code) $ git status
  157. # On branch 1.3_SF2046815_missing_entity_control_code
  158. # Changes to be committed:
  159. # (use "git reset HEAD <file>..." to unstage)
  160. #
  161. # modified: sql/Pg-database.sql
  162. #
  163. If you want to review the diff again once the index has been
  164. updated, use git diff --cached.
  165. Commiting Your Changes Locally
  166. ------------------------------
  167. The above git status output looks good, we're ready to commit
  168. locally:
  169. (1.3_SF2046815_missing_entity_control_code) $ git commit -m 'add missing entity.control_code column'
  170. Created commit a3503cb: add missing entity.control_code column
  171. 1 files changed, 1 insertions(+), 0 deletions(-)
  172. Commiters: Push Upstream With dcommit
  173. -------------------------------------
  174. If you have commit rights to the SourceForge repository, you can
  175. git svn dcommit your local commits directly.
  176. Update your bugfix branch with git svn rebase first:
  177. (1.3_SF2046815_missing_entity_control_code) $ git svn rebase
  178. Current branch 1.3_SF2046815_missing_entity_control_code is up to date.
  179. Now, you can git svn dcommit one or more commits on this branch
  180. which are not yet in the upstream subversion repository:
  181. (1.3_SF2046815_missing_entity_control_code) $ git svn dcommit
  182. Committing to https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk ...
  183. Authentication realm: <https://ledger-smb.svn.sourceforge.net:443> SourceForge Subversion area
  184. Username: einhverfr
  185. Password for 'einhverfr':
  186. M INSTALL
  187. Committed r2253
  188. M INSTALL
  189. r2253 = dcc0556bd0e1db3a4fc0788f2e60b62fa0c3378d (trunk)
  190. No changes between current HEAD and refs/remotes/trunk
  191. Resetting to the latest refs/remotes/trunk
  192. (Note: The above upstream commit is simulated for the purposes
  193. of this tutorial)
  194. Or, Generate A Patch
  195. --------------------
  196. If you don't have commit rights, and you're simply patching a
  197. bug from the tracker, make a diff of your mature/completed bug
  198. branch to its origin branch appropriate documentation:
  199. (1.3_SF2046815_missing_entity_control_code) $ git diff trunk > 1.3_SF2046815_missing_entity_control_code.diff
  200. And upload 1.3_SF2046815_missing_entity_control_code.diff as a
  201. patch with appropriate documentation.
  202. Example: Removing a File
  203. ------------------------
  204. Dubbed 'the stupid content tracker', git can guess at content
  205. changes to track renames. However, git handles the usual
  206. operations of add, delete, rename to best and most predictable
  207. effect if you use the git {mv,rm} form to explicitly tell git
  208. the intent of your layout changes.
  209. In this example, we are removing the outdated README.svn-status
  210. file. We don't need to make a branch for this small change.
  211. Rebase your current remote-tracking branch to the latest
  212. revision:
  213. (1.3_jfkw) $ git svn rebase
  214. Current branch 1.3_jfkw is up to date.
  215. Delete the file:
  216. (1.3_jfkw) $ git rm README.svn-status
  217. rm 'README.svn-status'
  218. This updates the index. Now examine 'your next commmit':
  219. (1.3_jfkw) $ git status
  220. # On branch 1.3_jfkw
  221. # Changes to be committed:
  222. # (use "git reset HEAD <file>..." to unstage)
  223. #
  224. # deleted: README.svn-status
  225. Looks good, commit the change:
  226. (1.3_jfkw) $ git commit -m 'remove outdated README.svn-status'
  227. Created commit 855a980: remove outdated README.svn-status
  228. 1 files changed, 0 insertions(+), 3 deletions(-)
  229. delete mode 100644 README.svn-status
  230. Here we find that git svn dcommit does the right thing with this
  231. kind of commit, too:
  232. (1.3_jfkw) $ git svn dcommit
  233. Committing to https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk ...
  234. D README.svn-status
  235. Committed r2314
  236. D README.svn-status
  237. r2314 = 93d75d87fb9300045f53ee3c8a585b2ecc402e4f (trunk)
  238. No changes between current HEAD and refs/remotes/trunk
  239. Resetting to the latest refs/remotes/trunk
  240. Note that we weren't asked for the username and password again.
  241. For a reality check using a subversion checkout, this changeset
  242. appears indistinguishable from one made with subversion itself.
  243. $ svn up /path/to/svn/ledgersmb13
  244. D /path/to/svn/ledgersmb13/README.svn-status
  245. Updated to revision 2314.
  246. $ svn log --limit 3 /path/to/svn/ledgersmb13
  247. --------------------------------------------------------------------
  248. r2314 | jfkw | 2008-09-04 18:12:12 -0400 (Thu, 04 Sep 2008) | 1 line
  249. remove outdated README.svn-status
  250. --------------------------------------------------------------------
  251. DVCS Participation Encouraged
  252. =============================
  253. The LedgerSMB developers welcome contributions of code and
  254. real-world testing. DVCS can be an effective way to conserve
  255. developer time, the LedgerSMB community's most limited resource.
  256. Developing with DVCS such as git will make it easier to
  257. communicate about LedgerSMB code. If you are doing work with
  258. LedgerSMB, DVCS makes it easier to review and if appropriate, to
  259. merge your mature feature branch upstream.
  260. Future additions to this document may include using a git
  261. hosting service such as gitorious or github. With a shared git
  262. repository you can share your branches with others who may want
  263. to collaborate or test. Best of all you can ask the LedgerSMB
  264. committers to pull from your repository when your branch is
  265. mature enough to be accepted upstream.
  266. If you're interested in using DVCS and git in particular to
  267. contribute to LedgerSMB, The author is available on #ledgersmb
  268. as jfkw or on the mailing list ledgersmb-dev.