You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo.go 61KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
8 years ago
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
8 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
10 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
7 years ago
9 years ago
7 years ago
7 years ago
9 years ago
9 years ago
9 years ago
7 years ago
7 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
10 years ago
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "html/template"
  10. "io/ioutil"
  11. "os"
  12. "os/exec"
  13. "path"
  14. "path/filepath"
  15. "regexp"
  16. "sort"
  17. "strings"
  18. "time"
  19. "code.gitea.io/git"
  20. "code.gitea.io/gitea/modules/bindata"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/markdown"
  23. "code.gitea.io/gitea/modules/process"
  24. "code.gitea.io/gitea/modules/setting"
  25. "code.gitea.io/gitea/modules/sync"
  26. api "code.gitea.io/sdk/gitea"
  27. "github.com/Unknwon/cae/zip"
  28. "github.com/Unknwon/com"
  29. "github.com/go-xorm/xorm"
  30. version "github.com/mcuadros/go-version"
  31. ini "gopkg.in/ini.v1"
  32. )
  33. const (
  34. tplUpdateHook = "#!/usr/bin/env %s\n%s update $1 $2 $3 --config='%s'\n"
  35. )
  36. var repoWorkingPool = sync.NewExclusivePool()
  37. var (
  38. ErrRepoFileNotExist = errors.New("Repository file does not exist")
  39. ErrRepoFileNotLoaded = errors.New("Repository file not loaded")
  40. ErrMirrorNotExist = errors.New("Mirror does not exist")
  41. ErrInvalidReference = errors.New("Invalid reference specified")
  42. ErrNameEmpty = errors.New("Name is empty")
  43. )
  44. var (
  45. Gitignores, Licenses, Readmes, LabelTemplates []string
  46. // Maximum items per page in forks, watchers and stars of a repo
  47. ItemsPerPage = 40
  48. )
  49. func LoadRepoConfig() {
  50. // Load .gitignore and license files and readme templates.
  51. types := []string{"gitignore", "license", "readme", "label"}
  52. typeFiles := make([][]string, 4)
  53. for i, t := range types {
  54. files, err := bindata.AssetDir("conf/" + t)
  55. if err != nil {
  56. log.Fatal(4, "Fail to get %s files: %v", t, err)
  57. }
  58. customPath := path.Join(setting.CustomPath, "conf", t)
  59. if com.IsDir(customPath) {
  60. customFiles, err := com.StatDir(customPath)
  61. if err != nil {
  62. log.Fatal(4, "Fail to get custom %s files: %v", t, err)
  63. }
  64. for _, f := range customFiles {
  65. if !com.IsSliceContainsStr(files, f) {
  66. files = append(files, f)
  67. }
  68. }
  69. }
  70. typeFiles[i] = files
  71. }
  72. Gitignores = typeFiles[0]
  73. Licenses = typeFiles[1]
  74. Readmes = typeFiles[2]
  75. LabelTemplates = typeFiles[3]
  76. sort.Strings(Gitignores)
  77. sort.Strings(Licenses)
  78. sort.Strings(Readmes)
  79. sort.Strings(LabelTemplates)
  80. // Filter out invalid names and promote preferred licenses.
  81. sortedLicenses := make([]string, 0, len(Licenses))
  82. for _, name := range setting.Repository.PreferredLicenses {
  83. if com.IsSliceContainsStr(Licenses, name) {
  84. sortedLicenses = append(sortedLicenses, name)
  85. }
  86. }
  87. for _, name := range Licenses {
  88. if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
  89. sortedLicenses = append(sortedLicenses, name)
  90. }
  91. }
  92. Licenses = sortedLicenses
  93. }
  94. func NewRepoContext() {
  95. zip.Verbose = false
  96. // Check Git installation.
  97. if _, err := exec.LookPath("git"); err != nil {
  98. log.Fatal(4, "Fail to test 'git' command: %v (forgotten install?)", err)
  99. }
  100. // Check Git version.
  101. gitVer, err := git.BinVersion()
  102. if err != nil {
  103. log.Fatal(4, "Fail to get Git version: %v", err)
  104. }
  105. log.Info("Git Version: %s", gitVer)
  106. if version.Compare("1.7.1", gitVer, ">") {
  107. log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
  108. }
  109. // Git requires setting user.name and user.email in order to commit changes.
  110. for configKey, defaultValue := range map[string]string{"user.name": "Gogs", "user.email": "gogs@fake.local"} {
  111. if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", configKey); err != nil || strings.TrimSpace(stdout) == "" {
  112. // ExitError indicates this config is not set
  113. if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
  114. if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
  115. log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr)
  116. }
  117. log.Info("Git config %s set to %s", configKey, defaultValue)
  118. } else {
  119. log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, stderr)
  120. }
  121. }
  122. }
  123. // Set git some configurations.
  124. if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)",
  125. "git", "config", "--global", "core.quotepath", "false"); err != nil {
  126. log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
  127. }
  128. RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
  129. }
  130. // Repository represents a git repository.
  131. type Repository struct {
  132. ID int64 `xorm:"pk autoincr"`
  133. OwnerID int64 `xorm:"UNIQUE(s)"`
  134. Owner *User `xorm:"-"`
  135. LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
  136. Name string `xorm:"INDEX NOT NULL"`
  137. Description string
  138. Website string
  139. DefaultBranch string
  140. NumWatches int
  141. NumStars int
  142. NumForks int
  143. NumIssues int
  144. NumClosedIssues int
  145. NumOpenIssues int `xorm:"-"`
  146. NumPulls int
  147. NumClosedPulls int
  148. NumOpenPulls int `xorm:"-"`
  149. NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
  150. NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
  151. NumOpenMilestones int `xorm:"-"`
  152. NumTags int `xorm:"-"`
  153. IsPrivate bool
  154. IsBare bool
  155. IsMirror bool
  156. *Mirror `xorm:"-"`
  157. // Advanced settings
  158. EnableWiki bool `xorm:"NOT NULL DEFAULT true"`
  159. EnableExternalWiki bool
  160. ExternalWikiURL string
  161. EnableIssues bool `xorm:"NOT NULL DEFAULT true"`
  162. EnableExternalTracker bool
  163. ExternalTrackerURL string
  164. ExternalTrackerFormat string
  165. ExternalTrackerStyle string
  166. ExternalMetas map[string]string `xorm:"-"`
  167. EnablePulls bool `xorm:"NOT NULL DEFAULT true"`
  168. IsFork bool `xorm:"NOT NULL DEFAULT false"`
  169. ForkID int64
  170. BaseRepo *Repository `xorm:"-"`
  171. Created time.Time `xorm:"-"`
  172. CreatedUnix int64
  173. Updated time.Time `xorm:"-"`
  174. UpdatedUnix int64
  175. }
  176. func (repo *Repository) BeforeInsert() {
  177. repo.CreatedUnix = time.Now().Unix()
  178. repo.UpdatedUnix = repo.CreatedUnix
  179. }
  180. func (repo *Repository) BeforeUpdate() {
  181. repo.UpdatedUnix = time.Now().Unix()
  182. }
  183. func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
  184. switch colName {
  185. case "default_branch":
  186. // FIXME: use models migration to solve all at once.
  187. if len(repo.DefaultBranch) == 0 {
  188. repo.DefaultBranch = "master"
  189. }
  190. case "num_closed_issues":
  191. repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
  192. case "num_closed_pulls":
  193. repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
  194. case "num_closed_milestones":
  195. repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
  196. case "external_tracker_style":
  197. if len(repo.ExternalTrackerStyle) == 0 {
  198. repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC
  199. }
  200. case "created_unix":
  201. repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
  202. case "updated_unix":
  203. repo.Updated = time.Unix(repo.UpdatedUnix, 0)
  204. }
  205. }
  206. // MustOwner always returns a valid *User object to avoid
  207. // conceptually impossible error handling.
  208. // It creates a fake object that contains error deftail
  209. // when error occurs.
  210. func (repo *Repository) MustOwner() *User {
  211. return repo.mustOwner(x)
  212. }
  213. func (repo *Repository) FullName() string {
  214. return repo.MustOwner().Name + "/" + repo.Name
  215. }
  216. func (repo *Repository) HTMLURL() string {
  217. return setting.AppUrl + repo.FullName()
  218. }
  219. // Arguments that are allowed to be nil: permission
  220. func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository {
  221. cloneLink := repo.CloneLink()
  222. return &api.Repository{
  223. ID: repo.ID,
  224. Owner: repo.Owner.APIFormat(),
  225. Name: repo.Name,
  226. FullName: repo.FullName(),
  227. Description: repo.Description,
  228. Private: repo.IsPrivate,
  229. Fork: repo.IsFork,
  230. HTMLURL: repo.HTMLURL(),
  231. SSHURL: cloneLink.SSH,
  232. CloneURL: cloneLink.HTTPS,
  233. Website: repo.Website,
  234. Stars: repo.NumStars,
  235. Forks: repo.NumForks,
  236. Watchers: repo.NumWatches,
  237. OpenIssues: repo.NumOpenIssues,
  238. DefaultBranch: repo.DefaultBranch,
  239. Created: repo.Created,
  240. Updated: repo.Updated,
  241. Permissions: permission,
  242. }
  243. }
  244. func (repo *Repository) getOwner(e Engine) (err error) {
  245. if repo.Owner != nil {
  246. return nil
  247. }
  248. repo.Owner, err = getUserByID(e, repo.OwnerID)
  249. return err
  250. }
  251. func (repo *Repository) GetOwner() error {
  252. return repo.getOwner(x)
  253. }
  254. func (repo *Repository) mustOwner(e Engine) *User {
  255. if err := repo.getOwner(e); err != nil {
  256. return &User{
  257. Name: "error",
  258. FullName: err.Error(),
  259. }
  260. }
  261. return repo.Owner
  262. }
  263. // ComposeMetas composes a map of metas for rendering external issue tracker URL.
  264. func (repo *Repository) ComposeMetas() map[string]string {
  265. if !repo.EnableExternalTracker {
  266. return nil
  267. } else if repo.ExternalMetas == nil {
  268. repo.ExternalMetas = map[string]string{
  269. "format": repo.ExternalTrackerFormat,
  270. "user": repo.MustOwner().Name,
  271. "repo": repo.Name,
  272. }
  273. switch repo.ExternalTrackerStyle {
  274. case markdown.ISSUE_NAME_STYLE_ALPHANUMERIC:
  275. repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_ALPHANUMERIC
  276. default:
  277. repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_NUMERIC
  278. }
  279. }
  280. return repo.ExternalMetas
  281. }
  282. // DeleteWiki removes the actual and local copy of repository wiki.
  283. func (repo *Repository) DeleteWiki() {
  284. wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
  285. for _, wikiPath := range wikiPaths {
  286. RemoveAllWithNotice("Delete repository wiki", wikiPath)
  287. }
  288. }
  289. func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
  290. if err = repo.getOwner(e); err != nil {
  291. return nil, err
  292. }
  293. accesses := make([]*Access, 0, 10)
  294. if err = e.
  295. Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite).
  296. Find(&accesses); err != nil {
  297. return nil, err
  298. }
  299. // Leave a seat for owner itself to append later, but if owner is an organization
  300. // and just waste 1 unit is cheaper than re-allocate memory once.
  301. users := make([]*User, 0, len(accesses)+1)
  302. if len(accesses) > 0 {
  303. userIDs := make([]int64, len(accesses))
  304. for i := 0; i < len(accesses); i++ {
  305. userIDs[i] = accesses[i].UserID
  306. }
  307. if err = e.In("id", userIDs).Find(&users); err != nil {
  308. return nil, err
  309. }
  310. }
  311. if !repo.Owner.IsOrganization() {
  312. users = append(users, repo.Owner)
  313. }
  314. return users, nil
  315. }
  316. // GetAssignees returns all users that have write access and can be assigned to issues
  317. // of the repository,
  318. func (repo *Repository) GetAssignees() (_ []*User, err error) {
  319. return repo.getAssignees(x)
  320. }
  321. // GetAssigneeByID returns the user that has write access of repository by given ID.
  322. func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) {
  323. return GetAssigneeByID(repo, userID)
  324. }
  325. // GetMilestoneByID returns the milestone belongs to repository by given ID.
  326. func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
  327. return GetMilestoneByRepoID(repo.ID, milestoneID)
  328. }
  329. // IssueStats returns number of open and closed repository issues by given filter mode.
  330. func (repo *Repository) IssueStats(uid int64, filterMode int, isPull bool) (int64, int64) {
  331. return GetRepoIssueStats(repo.ID, uid, filterMode, isPull)
  332. }
  333. func (repo *Repository) GetMirror() (err error) {
  334. repo.Mirror, err = GetMirrorByRepoID(repo.ID)
  335. return err
  336. }
  337. func (repo *Repository) GetBaseRepo() (err error) {
  338. if !repo.IsFork {
  339. return nil
  340. }
  341. repo.BaseRepo, err = GetRepositoryByID(repo.ForkID)
  342. return err
  343. }
  344. func (repo *Repository) repoPath(e Engine) string {
  345. return RepoPath(repo.mustOwner(e).Name, repo.Name)
  346. }
  347. func (repo *Repository) RepoPath() string {
  348. return repo.repoPath(x)
  349. }
  350. func (repo *Repository) GitConfigPath() string {
  351. return filepath.Join(repo.RepoPath(), "config")
  352. }
  353. func (repo *Repository) RelLink() string {
  354. return "/" + repo.FullName()
  355. }
  356. func (repo *Repository) Link() string {
  357. return setting.AppSubUrl + "/" + repo.FullName()
  358. }
  359. func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string {
  360. return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
  361. }
  362. func (repo *Repository) HasAccess(u *User) bool {
  363. has, _ := HasAccess(u, repo, AccessModeRead)
  364. return has
  365. }
  366. func (repo *Repository) IsOwnedBy(userID int64) bool {
  367. return repo.OwnerID == userID
  368. }
  369. // CanBeForked returns true if repository meets the requirements of being forked.
  370. func (repo *Repository) CanBeForked() bool {
  371. return !repo.IsBare
  372. }
  373. // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
  374. func (repo *Repository) CanEnablePulls() bool {
  375. return !repo.IsMirror
  376. }
  377. // AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
  378. func (repo *Repository) AllowsPulls() bool {
  379. return repo.CanEnablePulls() && repo.EnablePulls
  380. }
  381. // CanEnableEditor returns true if repository meets the requirements of web editor.
  382. func (repo *Repository) CanEnableEditor() bool {
  383. return !repo.IsMirror
  384. }
  385. // FIXME: should have a mutex to prevent producing same index for two issues that are created
  386. // closely enough.
  387. func (repo *Repository) NextIssueIndex() int64 {
  388. return int64(repo.NumIssues+repo.NumPulls) + 1
  389. }
  390. var (
  391. DescPattern = regexp.MustCompile(`https?://\S+`)
  392. )
  393. // DescriptionHtml does special handles to description and return HTML string.
  394. func (repo *Repository) DescriptionHtml() template.HTML {
  395. sanitize := func(s string) string {
  396. return fmt.Sprintf(`<a href="%[1]s" target="_blank">%[1]s</a>`, s)
  397. }
  398. return template.HTML(DescPattern.ReplaceAllStringFunc(markdown.Sanitizer.Sanitize(repo.Description), sanitize))
  399. }
  400. func (repo *Repository) LocalCopyPath() string {
  401. return path.Join(setting.AppDataPath, "tmp/local-rpeo", com.ToStr(repo.ID))
  402. }
  403. // UpdateLocalCopy pulls latest changes of given branch from repoPath to localPath.
  404. // It creates a new clone if local copy does not exist.
  405. // This function checks out target branch by default, it is safe to assume subsequent
  406. // operations are operating against target branch when caller has confidence for no race condition.
  407. func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
  408. if !com.IsExist(localPath) {
  409. if err := git.Clone(repoPath, localPath, git.CloneRepoOptions{
  410. Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
  411. Branch: branch,
  412. }); err != nil {
  413. return fmt.Errorf("git clone %s: %v", branch, err)
  414. }
  415. } else {
  416. if err := git.Checkout(localPath, git.CheckoutOptions{
  417. Branch: branch,
  418. }); err != nil {
  419. return fmt.Errorf("git checkout %s: %v", branch, err)
  420. }
  421. if err := git.Pull(localPath, git.PullRemoteOptions{
  422. Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
  423. Remote: "origin",
  424. Branch: branch,
  425. }); err != nil {
  426. return fmt.Errorf("git pull origin %s: %v", branch, err)
  427. }
  428. }
  429. return nil
  430. }
  431. // UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
  432. func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
  433. return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
  434. }
  435. // PatchPath returns corresponding patch file path of repository by given issue ID.
  436. func (repo *Repository) PatchPath(index int64) (string, error) {
  437. if err := repo.GetOwner(); err != nil {
  438. return "", err
  439. }
  440. return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil
  441. }
  442. // SavePatch saves patch data to corresponding location by given issue ID.
  443. func (repo *Repository) SavePatch(index int64, patch []byte) error {
  444. patchPath, err := repo.PatchPath(index)
  445. if err != nil {
  446. return fmt.Errorf("PatchPath: %v", err)
  447. }
  448. os.MkdirAll(filepath.Dir(patchPath), os.ModePerm)
  449. if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil {
  450. return fmt.Errorf("WriteFile: %v", err)
  451. }
  452. return nil
  453. }
  454. func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
  455. has, err := e.Get(&Repository{
  456. OwnerID: u.ID,
  457. LowerName: strings.ToLower(repoName),
  458. })
  459. return has && com.IsDir(RepoPath(u.Name, repoName)), err
  460. }
  461. // IsRepositoryExist returns true if the repository with given name under user has already existed.
  462. func IsRepositoryExist(u *User, repoName string) (bool, error) {
  463. return isRepositoryExist(x, u, repoName)
  464. }
  465. // CloneLink represents different types of clone URLs of repository.
  466. type CloneLink struct {
  467. SSH string
  468. HTTPS string
  469. Git string
  470. }
  471. // ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
  472. func ComposeHTTPSCloneURL(owner, repo string) string {
  473. return fmt.Sprintf("%s%s/%s.git", setting.AppUrl, owner, repo)
  474. }
  475. func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
  476. repoName := repo.Name
  477. if isWiki {
  478. repoName += ".wiki"
  479. }
  480. repo.Owner = repo.MustOwner()
  481. cl := new(CloneLink)
  482. if setting.SSH.Port != 22 {
  483. cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
  484. } else {
  485. cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  486. }
  487. cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repoName)
  488. return cl
  489. }
  490. // CloneLink returns clone URLs of repository.
  491. func (repo *Repository) CloneLink() (cl *CloneLink) {
  492. return repo.cloneLink(false)
  493. }
  494. type MigrateRepoOptions struct {
  495. Name string
  496. Description string
  497. IsPrivate bool
  498. IsMirror bool
  499. RemoteAddr string
  500. }
  501. /*
  502. GitHub, GitLab, Gogs: *.wiki.git
  503. BitBucket: *.git/wiki
  504. */
  505. var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
  506. // wikiRemoteURL returns accessible repository URL for wiki if exists.
  507. // Otherwise, it returns an empty string.
  508. func wikiRemoteURL(remote string) string {
  509. remote = strings.TrimSuffix(remote, ".git")
  510. for _, suffix := range commonWikiURLSuffixes {
  511. wikiURL := remote + suffix
  512. if git.IsRepoURLAccessible(wikiURL) {
  513. return wikiURL
  514. }
  515. }
  516. return ""
  517. }
  518. // MigrateRepository migrates a existing repository from other project hosting.
  519. func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
  520. repo, err := CreateRepository(u, CreateRepoOptions{
  521. Name: opts.Name,
  522. Description: opts.Description,
  523. IsPrivate: opts.IsPrivate,
  524. IsMirror: opts.IsMirror,
  525. })
  526. if err != nil {
  527. return nil, err
  528. }
  529. repoPath := RepoPath(u.Name, opts.Name)
  530. wikiPath := WikiPath(u.Name, opts.Name)
  531. if u.IsOrganization() {
  532. t, err := u.GetOwnerTeam()
  533. if err != nil {
  534. return nil, err
  535. }
  536. repo.NumWatches = t.NumMembers
  537. } else {
  538. repo.NumWatches = 1
  539. }
  540. migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
  541. os.RemoveAll(repoPath)
  542. if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
  543. Mirror: true,
  544. Quiet: true,
  545. Timeout: migrateTimeout,
  546. }); err != nil {
  547. return repo, fmt.Errorf("Clone: %v", err)
  548. }
  549. wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
  550. if len(wikiRemotePath) > 0 {
  551. os.RemoveAll(wikiPath)
  552. if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
  553. Mirror: true,
  554. Quiet: true,
  555. Timeout: migrateTimeout,
  556. }); err != nil {
  557. log.Info("Clone wiki: %v", err)
  558. }
  559. }
  560. // Check if repository is empty.
  561. _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
  562. if err != nil {
  563. if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
  564. repo.IsBare = true
  565. } else {
  566. return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
  567. }
  568. }
  569. if !repo.IsBare {
  570. // Try to get HEAD branch and set it as default branch.
  571. gitRepo, err := git.OpenRepository(repoPath)
  572. if err != nil {
  573. return repo, fmt.Errorf("OpenRepository: %v", err)
  574. }
  575. headBranch, err := gitRepo.GetHEADBranch()
  576. if err != nil {
  577. return repo, fmt.Errorf("GetHEADBranch: %v", err)
  578. }
  579. if headBranch != nil {
  580. repo.DefaultBranch = headBranch.Name
  581. }
  582. }
  583. if opts.IsMirror {
  584. if _, err = x.InsertOne(&Mirror{
  585. RepoID: repo.ID,
  586. Interval: setting.Mirror.DefaultInterval,
  587. EnablePrune: true,
  588. NextUpdate: time.Now().Add(time.Duration(setting.Mirror.DefaultInterval) * time.Hour),
  589. }); err != nil {
  590. return repo, fmt.Errorf("InsertOne: %v", err)
  591. }
  592. repo.IsMirror = true
  593. return repo, UpdateRepository(repo, false)
  594. }
  595. return CleanUpMigrateInfo(repo)
  596. }
  597. // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
  598. // This also removes possible user credentials.
  599. func cleanUpMigrateGitConfig(configPath string) error {
  600. cfg, err := ini.Load(configPath)
  601. if err != nil {
  602. return fmt.Errorf("open config file: %v", err)
  603. }
  604. cfg.DeleteSection("remote \"origin\"")
  605. if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
  606. return fmt.Errorf("save config file: %v", err)
  607. }
  608. return nil
  609. }
  610. func createUpdateHook(repoPath string) error {
  611. return git.SetUpdateHook(repoPath,
  612. fmt.Sprintf(tplUpdateHook, setting.ScriptType, "\""+setting.AppPath+"\"", setting.CustomConf))
  613. }
  614. // Finish migrating repository and/or wiki with things that don't need to be done for mirrors.
  615. func CleanUpMigrateInfo(repo *Repository) (*Repository, error) {
  616. repoPath := repo.RepoPath()
  617. if err := createUpdateHook(repoPath); err != nil {
  618. return repo, fmt.Errorf("createUpdateHook: %v", err)
  619. }
  620. if repo.HasWiki() {
  621. if err := createUpdateHook(repo.WikiPath()); err != nil {
  622. return repo, fmt.Errorf("createUpdateHook (wiki): %v", err)
  623. }
  624. }
  625. if err := cleanUpMigrateGitConfig(repo.GitConfigPath()); err != nil {
  626. return repo, fmt.Errorf("cleanUpMigrateGitConfig: %v", err)
  627. }
  628. if repo.HasWiki() {
  629. if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
  630. return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
  631. }
  632. }
  633. return repo, UpdateRepository(repo, false)
  634. }
  635. // initRepoCommit temporarily changes with work directory.
  636. func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
  637. var stderr string
  638. if _, stderr, err = process.ExecDir(-1,
  639. tmpPath, fmt.Sprintf("initRepoCommit (git add): %s", tmpPath),
  640. "git", "add", "--all"); err != nil {
  641. return fmt.Errorf("git add: %s", stderr)
  642. }
  643. if _, stderr, err = process.ExecDir(-1,
  644. tmpPath, fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath),
  645. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  646. "-m", "Initial commit"); err != nil {
  647. return fmt.Errorf("git commit: %s", stderr)
  648. }
  649. if _, stderr, err = process.ExecDir(-1,
  650. tmpPath, fmt.Sprintf("initRepoCommit (git push): %s", tmpPath),
  651. "git", "push", "origin", "master"); err != nil {
  652. return fmt.Errorf("git push: %s", stderr)
  653. }
  654. return nil
  655. }
  656. type CreateRepoOptions struct {
  657. Name string
  658. Description string
  659. Gitignores string
  660. License string
  661. Readme string
  662. IsPrivate bool
  663. IsMirror bool
  664. AutoInit bool
  665. }
  666. func getRepoInitFile(tp, name string) ([]byte, error) {
  667. relPath := path.Join("conf", tp, strings.TrimLeft(name, "./"))
  668. // Use custom file when available.
  669. customPath := path.Join(setting.CustomPath, relPath)
  670. if com.IsFile(customPath) {
  671. return ioutil.ReadFile(customPath)
  672. }
  673. return bindata.Asset(relPath)
  674. }
  675. func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
  676. // Clone to temprory path and do the init commit.
  677. _, stderr, err := process.Exec(
  678. fmt.Sprintf("initRepository(git clone): %s", repoPath), "git", "clone", repoPath, tmpDir)
  679. if err != nil {
  680. return fmt.Errorf("git clone: %v - %s", err, stderr)
  681. }
  682. // README
  683. data, err := getRepoInitFile("readme", opts.Readme)
  684. if err != nil {
  685. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
  686. }
  687. cloneLink := repo.CloneLink()
  688. match := map[string]string{
  689. "Name": repo.Name,
  690. "Description": repo.Description,
  691. "CloneURL.SSH": cloneLink.SSH,
  692. "CloneURL.HTTPS": cloneLink.HTTPS,
  693. }
  694. if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
  695. []byte(com.Expand(string(data), match)), 0644); err != nil {
  696. return fmt.Errorf("write README.md: %v", err)
  697. }
  698. // .gitignore
  699. if len(opts.Gitignores) > 0 {
  700. var buf bytes.Buffer
  701. names := strings.Split(opts.Gitignores, ",")
  702. for _, name := range names {
  703. data, err = getRepoInitFile("gitignore", name)
  704. if err != nil {
  705. return fmt.Errorf("getRepoInitFile[%s]: %v", name, err)
  706. }
  707. buf.WriteString("# ---> " + name + "\n")
  708. buf.Write(data)
  709. buf.WriteString("\n")
  710. }
  711. if buf.Len() > 0 {
  712. if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
  713. return fmt.Errorf("write .gitignore: %v", err)
  714. }
  715. }
  716. }
  717. // LICENSE
  718. if len(opts.License) > 0 {
  719. data, err = getRepoInitFile("license", opts.License)
  720. if err != nil {
  721. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
  722. }
  723. if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
  724. return fmt.Errorf("write LICENSE: %v", err)
  725. }
  726. }
  727. return nil
  728. }
  729. // InitRepository initializes README and .gitignore if needed.
  730. func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts CreateRepoOptions) (err error) {
  731. // Somehow the directory could exist.
  732. if com.IsExist(repoPath) {
  733. return fmt.Errorf("initRepository: path already exists: %s", repoPath)
  734. }
  735. // Init bare new repository.
  736. if err = git.InitRepository(repoPath, true); err != nil {
  737. return fmt.Errorf("InitRepository: %v", err)
  738. } else if err = createUpdateHook(repoPath); err != nil {
  739. return fmt.Errorf("createUpdateHook: %v", err)
  740. }
  741. tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  742. // Initialize repository according to user's choice.
  743. if opts.AutoInit {
  744. os.MkdirAll(tmpDir, os.ModePerm)
  745. defer os.RemoveAll(tmpDir)
  746. if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
  747. return fmt.Errorf("prepareRepoCommit: %v", err)
  748. }
  749. // Apply changes and commit.
  750. if err = initRepoCommit(tmpDir, u.NewGitSig()); err != nil {
  751. return fmt.Errorf("initRepoCommit: %v", err)
  752. }
  753. }
  754. // Re-fetch the repository from database before updating it (else it would
  755. // override changes that were done earlier with sql)
  756. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  757. return fmt.Errorf("getRepositoryByID: %v", err)
  758. }
  759. if !opts.AutoInit {
  760. repo.IsBare = true
  761. }
  762. repo.DefaultBranch = "master"
  763. if err = updateRepository(e, repo, false); err != nil {
  764. return fmt.Errorf("updateRepository: %v", err)
  765. }
  766. return nil
  767. }
  768. var (
  769. reservedRepoNames = []string{".", ".."}
  770. reservedRepoPatterns = []string{"*.git", "*.wiki"}
  771. )
  772. func IsUsableRepoName(name string) error {
  773. return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
  774. }
  775. func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
  776. if err = IsUsableRepoName(repo.Name); err != nil {
  777. return err
  778. }
  779. has, err := isRepositoryExist(e, u, repo.Name)
  780. if err != nil {
  781. return fmt.Errorf("IsRepositoryExist: %v", err)
  782. } else if has {
  783. return ErrRepoAlreadyExist{u.Name, repo.Name}
  784. }
  785. if _, err = e.Insert(repo); err != nil {
  786. return err
  787. }
  788. u.NumRepos++
  789. // Remember visibility preference.
  790. u.LastRepoVisibility = repo.IsPrivate
  791. if err = updateUser(e, u); err != nil {
  792. return fmt.Errorf("updateUser: %v", err)
  793. }
  794. // Give access to all members in owner team.
  795. if u.IsOrganization() {
  796. t, err := u.getOwnerTeam(e)
  797. if err != nil {
  798. return fmt.Errorf("getOwnerTeam: %v", err)
  799. } else if err = t.addRepository(e, repo); err != nil {
  800. return fmt.Errorf("addRepository: %v", err)
  801. }
  802. } else {
  803. // Organization automatically called this in addRepository method.
  804. if err = repo.recalculateAccesses(e); err != nil {
  805. return fmt.Errorf("recalculateAccesses: %v", err)
  806. }
  807. }
  808. if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
  809. return fmt.Errorf("watchRepo: %v", err)
  810. } else if err = newRepoAction(e, u, repo); err != nil {
  811. return fmt.Errorf("newRepoAction: %v", err)
  812. }
  813. return nil
  814. }
  815. // CreateRepository creates a repository for given user or organization.
  816. func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error) {
  817. if !u.CanCreateRepo() {
  818. return nil, ErrReachLimitOfRepo{u.MaxRepoCreation}
  819. }
  820. repo := &Repository{
  821. OwnerID: u.ID,
  822. Owner: u,
  823. Name: opts.Name,
  824. LowerName: strings.ToLower(opts.Name),
  825. Description: opts.Description,
  826. IsPrivate: opts.IsPrivate,
  827. EnableWiki: true,
  828. EnableIssues: true,
  829. EnablePulls: true,
  830. }
  831. sess := x.NewSession()
  832. defer sessionRelease(sess)
  833. if err = sess.Begin(); err != nil {
  834. return nil, err
  835. }
  836. if err = createRepository(sess, u, repo); err != nil {
  837. return nil, err
  838. }
  839. // No need for init mirror.
  840. if !opts.IsMirror {
  841. repoPath := RepoPath(u.Name, repo.Name)
  842. if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
  843. if err2 := os.RemoveAll(repoPath); err2 != nil {
  844. log.Error(4, "initRepository: %v", err)
  845. return nil, fmt.Errorf(
  846. "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
  847. }
  848. return nil, fmt.Errorf("initRepository: %v", err)
  849. }
  850. _, stderr, err := process.ExecDir(-1,
  851. repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath),
  852. "git", "update-server-info")
  853. if err != nil {
  854. return nil, errors.New("CreateRepository(git update-server-info): " + stderr)
  855. }
  856. }
  857. return repo, sess.Commit()
  858. }
  859. func countRepositories(userID int64, private bool) int64 {
  860. sess := x.Where("id > 0")
  861. if userID > 0 {
  862. sess.And("owner_id = ?", userID)
  863. }
  864. if !private {
  865. sess.And("is_private=?", false)
  866. }
  867. count, err := sess.Count(new(Repository))
  868. if err != nil {
  869. log.Error(4, "countRepositories: %v", err)
  870. }
  871. return count
  872. }
  873. // CountRepositories returns number of repositories.
  874. // Argument private only takes effect when it is false,
  875. // set it true to count all repositories.
  876. func CountRepositories(private bool) int64 {
  877. return countRepositories(-1, private)
  878. }
  879. // CountUserRepositories returns number of repositories user owns.
  880. // Argument private only takes effect when it is false,
  881. // set it true to count all repositories.
  882. func CountUserRepositories(userID int64, private bool) int64 {
  883. return countRepositories(userID, private)
  884. }
  885. func Repositories(page, pageSize int) (_ []*Repository, err error) {
  886. repos := make([]*Repository, 0, pageSize)
  887. return repos, x.Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&repos)
  888. }
  889. // RepositoriesWithUsers returns number of repos in given page.
  890. func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) {
  891. repos, err := Repositories(page, pageSize)
  892. if err != nil {
  893. return nil, fmt.Errorf("Repositories: %v", err)
  894. }
  895. for i := range repos {
  896. if err = repos[i].GetOwner(); err != nil {
  897. return nil, err
  898. }
  899. }
  900. return repos, nil
  901. }
  902. // RepoPath returns repository path by given user and repository name.
  903. func RepoPath(userName, repoName string) string {
  904. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  905. }
  906. // TransferOwnership transfers all corresponding setting from old user to new one.
  907. func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error {
  908. newOwner, err := GetUserByName(newOwnerName)
  909. if err != nil {
  910. return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
  911. }
  912. // Check if new owner has repository with same name.
  913. has, err := IsRepositoryExist(newOwner, repo.Name)
  914. if err != nil {
  915. return fmt.Errorf("IsRepositoryExist: %v", err)
  916. } else if has {
  917. return ErrRepoAlreadyExist{newOwnerName, repo.Name}
  918. }
  919. sess := x.NewSession()
  920. defer sessionRelease(sess)
  921. if err = sess.Begin(); err != nil {
  922. return fmt.Errorf("sess.Begin: %v", err)
  923. }
  924. owner := repo.Owner
  925. // Note: we have to set value here to make sure recalculate accesses is based on
  926. // new owner.
  927. repo.OwnerID = newOwner.ID
  928. repo.Owner = newOwner
  929. // Update repository.
  930. if _, err := sess.Id(repo.ID).Update(repo); err != nil {
  931. return fmt.Errorf("update owner: %v", err)
  932. }
  933. // Remove redundant collaborators.
  934. collaborators, err := repo.getCollaborators(sess)
  935. if err != nil {
  936. return fmt.Errorf("getCollaborators: %v", err)
  937. }
  938. // Dummy object.
  939. collaboration := &Collaboration{RepoID: repo.ID}
  940. for _, c := range collaborators {
  941. collaboration.UserID = c.ID
  942. if c.ID == newOwner.ID || newOwner.IsOrgMember(c.ID) {
  943. if _, err = sess.Delete(collaboration); err != nil {
  944. return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
  945. }
  946. }
  947. }
  948. // Remove old team-repository relations.
  949. if owner.IsOrganization() {
  950. if err = owner.getTeams(sess); err != nil {
  951. return fmt.Errorf("getTeams: %v", err)
  952. }
  953. for _, t := range owner.Teams {
  954. if !t.hasRepository(sess, repo.ID) {
  955. continue
  956. }
  957. t.NumRepos--
  958. if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil {
  959. return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
  960. }
  961. }
  962. if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
  963. return fmt.Errorf("removeOrgRepo: %v", err)
  964. }
  965. }
  966. if newOwner.IsOrganization() {
  967. t, err := newOwner.getOwnerTeam(sess)
  968. if err != nil {
  969. return fmt.Errorf("getOwnerTeam: %v", err)
  970. } else if err = t.addRepository(sess, repo); err != nil {
  971. return fmt.Errorf("add to owner team: %v", err)
  972. }
  973. } else {
  974. // Organization called this in addRepository method.
  975. if err = repo.recalculateAccesses(sess); err != nil {
  976. return fmt.Errorf("recalculateAccesses: %v", err)
  977. }
  978. }
  979. // Update repository count.
  980. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
  981. return fmt.Errorf("increase new owner repository count: %v", err)
  982. } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
  983. return fmt.Errorf("decrease old owner repository count: %v", err)
  984. }
  985. if err = watchRepo(sess, newOwner.ID, repo.ID, true); err != nil {
  986. return fmt.Errorf("watchRepo: %v", err)
  987. } else if err = transferRepoAction(sess, doer, owner, repo); err != nil {
  988. return fmt.Errorf("transferRepoAction: %v", err)
  989. }
  990. // Rename remote repository to new path and delete local copy.
  991. os.MkdirAll(UserPath(newOwner.Name), os.ModePerm)
  992. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
  993. return fmt.Errorf("rename repository directory: %v", err)
  994. }
  995. RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath())
  996. // Rename remote wiki repository to new path and delete local copy.
  997. wikiPath := WikiPath(owner.Name, repo.Name)
  998. if com.IsExist(wikiPath) {
  999. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1000. if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
  1001. return fmt.Errorf("rename repository wiki: %v", err)
  1002. }
  1003. }
  1004. return sess.Commit()
  1005. }
  1006. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  1007. func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) {
  1008. oldRepoName = strings.ToLower(oldRepoName)
  1009. newRepoName = strings.ToLower(newRepoName)
  1010. if err = IsUsableRepoName(newRepoName); err != nil {
  1011. return err
  1012. }
  1013. has, err := IsRepositoryExist(u, newRepoName)
  1014. if err != nil {
  1015. return fmt.Errorf("IsRepositoryExist: %v", err)
  1016. } else if has {
  1017. return ErrRepoAlreadyExist{u.Name, newRepoName}
  1018. }
  1019. repo, err := GetRepositoryByName(u.ID, oldRepoName)
  1020. if err != nil {
  1021. return fmt.Errorf("GetRepositoryByName: %v", err)
  1022. }
  1023. // Change repository directory name.
  1024. if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
  1025. return fmt.Errorf("rename repository directory: %v", err)
  1026. }
  1027. wikiPath := repo.WikiPath()
  1028. if com.IsExist(wikiPath) {
  1029. if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
  1030. return fmt.Errorf("rename repository wiki: %v", err)
  1031. }
  1032. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1033. }
  1034. return nil
  1035. }
  1036. func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {
  1037. repos := make([]*Repository, 0, 10)
  1038. return repos, e.
  1039. Where("fork_id=?", forkID).
  1040. Find(&repos)
  1041. }
  1042. // GetRepositoriesByForkID returns all repositories with given fork ID.
  1043. func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
  1044. return getRepositoriesByForkID(x, forkID)
  1045. }
  1046. func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
  1047. repo.LowerName = strings.ToLower(repo.Name)
  1048. if len(repo.Description) > 255 {
  1049. repo.Description = repo.Description[:255]
  1050. }
  1051. if len(repo.Website) > 255 {
  1052. repo.Website = repo.Website[:255]
  1053. }
  1054. if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
  1055. return fmt.Errorf("update: %v", err)
  1056. }
  1057. if visibilityChanged {
  1058. if err = repo.getOwner(e); err != nil {
  1059. return fmt.Errorf("getOwner: %v", err)
  1060. }
  1061. if repo.Owner.IsOrganization() {
  1062. // Organization repository need to recalculate access table when visivility is changed.
  1063. if err = repo.recalculateTeamAccesses(e, 0); err != nil {
  1064. return fmt.Errorf("recalculateTeamAccesses: %v", err)
  1065. }
  1066. }
  1067. // Create/Remove git-daemon-export-ok for git-daemon...
  1068. daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
  1069. if repo.IsPrivate && com.IsExist(daemonExportFile) {
  1070. if err = os.Remove(daemonExportFile); err != nil {
  1071. log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
  1072. }
  1073. } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
  1074. if f, err := os.Create(daemonExportFile); err != nil {
  1075. log.Error(4, "Failed to create %s: %v", daemonExportFile, err)
  1076. } else {
  1077. f.Close()
  1078. }
  1079. }
  1080. forkRepos, err := getRepositoriesByForkID(e, repo.ID)
  1081. if err != nil {
  1082. return fmt.Errorf("getRepositoriesByForkID: %v", err)
  1083. }
  1084. for i := range forkRepos {
  1085. forkRepos[i].IsPrivate = repo.IsPrivate
  1086. if err = updateRepository(e, forkRepos[i], true); err != nil {
  1087. return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
  1088. }
  1089. }
  1090. }
  1091. return nil
  1092. }
  1093. func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
  1094. sess := x.NewSession()
  1095. defer sessionRelease(sess)
  1096. if err = sess.Begin(); err != nil {
  1097. return err
  1098. }
  1099. if err = updateRepository(x, repo, visibilityChanged); err != nil {
  1100. return fmt.Errorf("updateRepository: %v", err)
  1101. }
  1102. return sess.Commit()
  1103. }
  1104. // DeleteRepository deletes a repository for a user or organization.
  1105. func DeleteRepository(uid, repoID int64) error {
  1106. repo := &Repository{ID: repoID, OwnerID: uid}
  1107. has, err := x.Get(repo)
  1108. if err != nil {
  1109. return err
  1110. } else if !has {
  1111. return ErrRepoNotExist{repoID, uid, ""}
  1112. }
  1113. // In case is a organization.
  1114. org, err := GetUserByID(uid)
  1115. if err != nil {
  1116. return err
  1117. }
  1118. if org.IsOrganization() {
  1119. if err = org.GetTeams(); err != nil {
  1120. return err
  1121. }
  1122. }
  1123. sess := x.NewSession()
  1124. defer sessionRelease(sess)
  1125. if err = sess.Begin(); err != nil {
  1126. return err
  1127. }
  1128. if org.IsOrganization() {
  1129. for _, t := range org.Teams {
  1130. if !t.hasRepository(sess, repoID) {
  1131. continue
  1132. } else if err = t.removeRepository(sess, repo, false); err != nil {
  1133. return err
  1134. }
  1135. }
  1136. }
  1137. if err = deleteBeans(sess,
  1138. &Repository{ID: repoID},
  1139. &Access{RepoID: repo.ID},
  1140. &Action{RepoID: repo.ID},
  1141. &Watch{RepoID: repoID},
  1142. &Star{RepoID: repoID},
  1143. &Mirror{RepoID: repoID},
  1144. &IssueUser{RepoID: repoID},
  1145. &Milestone{RepoID: repoID},
  1146. &Release{RepoID: repoID},
  1147. &Collaboration{RepoID: repoID},
  1148. &PullRequest{BaseRepoID: repoID},
  1149. ); err != nil {
  1150. return fmt.Errorf("deleteBeans: %v", err)
  1151. }
  1152. // Delete comments and attachments.
  1153. issues := make([]*Issue, 0, 25)
  1154. attachmentPaths := make([]string, 0, len(issues))
  1155. if err = sess.
  1156. Where("repo_id=?", repoID).
  1157. Find(&issues); err != nil {
  1158. return err
  1159. }
  1160. for i := range issues {
  1161. if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil {
  1162. return err
  1163. }
  1164. attachments := make([]*Attachment, 0, 5)
  1165. if err = sess.
  1166. Where("issue_id=?", issues[i].ID).
  1167. Find(&attachments); err != nil {
  1168. return err
  1169. }
  1170. for j := range attachments {
  1171. attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
  1172. }
  1173. if _, err = sess.Delete(&Attachment{IssueID: issues[i].ID}); err != nil {
  1174. return err
  1175. }
  1176. }
  1177. if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
  1178. return err
  1179. }
  1180. if repo.IsFork {
  1181. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
  1182. return fmt.Errorf("decrease fork count: %v", err)
  1183. }
  1184. }
  1185. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
  1186. return err
  1187. }
  1188. // Remove repository files.
  1189. repoPath := repo.repoPath(sess)
  1190. RemoveAllWithNotice("Delete repository files", repoPath)
  1191. repo.DeleteWiki()
  1192. // Remove attachment files.
  1193. for i := range attachmentPaths {
  1194. RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
  1195. }
  1196. if err = sess.Commit(); err != nil {
  1197. return fmt.Errorf("Commit: %v", err)
  1198. }
  1199. if repo.NumForks > 0 {
  1200. if _, err = x.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
  1201. log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
  1202. }
  1203. }
  1204. return nil
  1205. }
  1206. // GetRepositoryByRef returns a Repository specified by a GFM reference.
  1207. // See https://help.github.com/articles/writing-on-github#references for more information on the syntax.
  1208. func GetRepositoryByRef(ref string) (*Repository, error) {
  1209. n := strings.IndexByte(ref, byte('/'))
  1210. if n < 2 {
  1211. return nil, ErrInvalidReference
  1212. }
  1213. userName, repoName := ref[:n], ref[n+1:]
  1214. user, err := GetUserByName(userName)
  1215. if err != nil {
  1216. return nil, err
  1217. }
  1218. return GetRepositoryByName(user.ID, repoName)
  1219. }
  1220. // GetRepositoryByName returns the repository by given name under user if exists.
  1221. func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
  1222. repo := &Repository{
  1223. OwnerID: ownerID,
  1224. LowerName: strings.ToLower(name),
  1225. }
  1226. has, err := x.Get(repo)
  1227. if err != nil {
  1228. return nil, err
  1229. } else if !has {
  1230. return nil, ErrRepoNotExist{0, ownerID, name}
  1231. }
  1232. return repo, err
  1233. }
  1234. func getRepositoryByID(e Engine, id int64) (*Repository, error) {
  1235. repo := new(Repository)
  1236. has, err := e.Id(id).Get(repo)
  1237. if err != nil {
  1238. return nil, err
  1239. } else if !has {
  1240. return nil, ErrRepoNotExist{id, 0, ""}
  1241. }
  1242. return repo, nil
  1243. }
  1244. // GetRepositoryByID returns the repository by given id if exists.
  1245. func GetRepositoryByID(id int64) (*Repository, error) {
  1246. return getRepositoryByID(x, id)
  1247. }
  1248. // GetUserRepositories returns a list of repositories of given user.
  1249. func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) {
  1250. sess := x.
  1251. Where("owner_id = ?", userID).
  1252. Desc("updated_unix")
  1253. if !private {
  1254. sess.And("is_private=?", false)
  1255. }
  1256. if page <= 0 {
  1257. page = 1
  1258. }
  1259. sess.Limit(pageSize, (page-1)*pageSize)
  1260. repos := make([]*Repository, 0, pageSize)
  1261. return repos, sess.Find(&repos)
  1262. }
  1263. // GetUserRepositories returns a list of mirror repositories of given user.
  1264. func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
  1265. repos := make([]*Repository, 0, 10)
  1266. return repos, x.
  1267. Where("owner_id = ?", userID).
  1268. And("is_mirror = ?", true).
  1269. Find(&repos)
  1270. }
  1271. // GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
  1272. func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err error) {
  1273. return repos, x.
  1274. Limit(pageSize, (page-1)*pageSize).
  1275. Where("is_private=?", false).
  1276. Limit(pageSize).
  1277. Desc("updated_unix").
  1278. Find(&repos)
  1279. }
  1280. func getRepositoryCount(e Engine, u *User) (int64, error) {
  1281. return x.Count(&Repository{OwnerID: u.ID})
  1282. }
  1283. // GetRepositoryCount returns the total number of repositories of user.
  1284. func GetRepositoryCount(u *User) (int64, error) {
  1285. return getRepositoryCount(x, u)
  1286. }
  1287. type SearchRepoOptions struct {
  1288. Keyword string
  1289. OwnerID int64
  1290. OrderBy string
  1291. Private bool // Include private repositories in results
  1292. Page int
  1293. PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
  1294. }
  1295. // SearchRepositoryByName takes keyword and part of repository name to search,
  1296. // it returns results in given range and number of total results.
  1297. func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int64, _ error) {
  1298. if len(opts.Keyword) == 0 {
  1299. return repos, 0, nil
  1300. }
  1301. opts.Keyword = strings.ToLower(opts.Keyword)
  1302. if opts.Page <= 0 {
  1303. opts.Page = 1
  1304. }
  1305. repos = make([]*Repository, 0, opts.PageSize)
  1306. // Append conditions
  1307. sess := x.Where("LOWER(lower_name) LIKE ?", "%"+opts.Keyword+"%")
  1308. if opts.OwnerID > 0 {
  1309. sess.And("owner_id = ?", opts.OwnerID)
  1310. }
  1311. if !opts.Private {
  1312. sess.And("is_private=?", false)
  1313. }
  1314. var countSess xorm.Session
  1315. countSess = *sess
  1316. count, err := countSess.Count(new(Repository))
  1317. if err != nil {
  1318. return nil, 0, fmt.Errorf("Count: %v", err)
  1319. }
  1320. if len(opts.OrderBy) > 0 {
  1321. sess.OrderBy(opts.OrderBy)
  1322. }
  1323. return repos, count, sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Find(&repos)
  1324. }
  1325. // DeleteRepositoryArchives deletes all repositories' archives.
  1326. func DeleteRepositoryArchives() error {
  1327. return x.
  1328. Where("id > 0").
  1329. Iterate(new(Repository),
  1330. func(idx int, bean interface{}) error {
  1331. repo := bean.(*Repository)
  1332. return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
  1333. })
  1334. }
  1335. func gatherMissingRepoRecords() ([]*Repository, error) {
  1336. repos := make([]*Repository, 0, 10)
  1337. if err := x.
  1338. Where("id > 0").
  1339. Iterate(new(Repository),
  1340. func(idx int, bean interface{}) error {
  1341. repo := bean.(*Repository)
  1342. if !com.IsDir(repo.RepoPath()) {
  1343. repos = append(repos, repo)
  1344. }
  1345. return nil
  1346. }); err != nil {
  1347. if err2 := CreateRepositoryNotice(fmt.Sprintf("gatherMissingRepoRecords: %v", err)); err2 != nil {
  1348. return nil, fmt.Errorf("CreateRepositoryNotice: %v", err)
  1349. }
  1350. }
  1351. return repos, nil
  1352. }
  1353. // DeleteMissingRepositories deletes all repository records that lost Git files.
  1354. func DeleteMissingRepositories() error {
  1355. repos, err := gatherMissingRepoRecords()
  1356. if err != nil {
  1357. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1358. }
  1359. if len(repos) == 0 {
  1360. return nil
  1361. }
  1362. for _, repo := range repos {
  1363. log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
  1364. if err := DeleteRepository(repo.OwnerID, repo.ID); err != nil {
  1365. if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1366. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1367. }
  1368. }
  1369. }
  1370. return nil
  1371. }
  1372. // ReinitMissingRepositories reinitializes all repository records that lost Git files.
  1373. func ReinitMissingRepositories() error {
  1374. repos, err := gatherMissingRepoRecords()
  1375. if err != nil {
  1376. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1377. }
  1378. if len(repos) == 0 {
  1379. return nil
  1380. }
  1381. for _, repo := range repos {
  1382. log.Trace("Initializing %d/%d...", repo.OwnerID, repo.ID)
  1383. if err := git.InitRepository(repo.RepoPath(), true); err != nil {
  1384. if err2 := CreateRepositoryNotice(fmt.Sprintf("InitRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1385. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1386. }
  1387. }
  1388. }
  1389. return nil
  1390. }
  1391. // RewriteRepositoryUpdateHook rewrites all repositories' update hook.
  1392. func RewriteRepositoryUpdateHook() error {
  1393. return x.
  1394. Where("id > 0").
  1395. Iterate(new(Repository),
  1396. func(idx int, bean interface{}) error {
  1397. repo := bean.(*Repository)
  1398. return createUpdateHook(repo.RepoPath())
  1399. })
  1400. }
  1401. // Prevent duplicate running tasks.
  1402. var taskStatusTable = sync.NewStatusTable()
  1403. const (
  1404. mirrorUpdate = "mirror_update"
  1405. gitFsck = "git_fsck"
  1406. checkRepos = "check_repos"
  1407. )
  1408. // GitFsck calls 'git fsck' to check repository health.
  1409. func GitFsck() {
  1410. if taskStatusTable.IsRunning(gitFsck) {
  1411. return
  1412. }
  1413. taskStatusTable.Start(gitFsck)
  1414. defer taskStatusTable.Stop(gitFsck)
  1415. log.Trace("Doing: GitFsck")
  1416. if err := x.
  1417. Where("id>0").
  1418. Iterate(new(Repository),
  1419. func(idx int, bean interface{}) error {
  1420. repo := bean.(*Repository)
  1421. repoPath := repo.RepoPath()
  1422. if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
  1423. desc := fmt.Sprintf("Fail to health check repository (%s): %v", repoPath, err)
  1424. log.Warn(desc)
  1425. if err = CreateRepositoryNotice(desc); err != nil {
  1426. log.Error(4, "CreateRepositoryNotice: %v", err)
  1427. }
  1428. }
  1429. return nil
  1430. }); err != nil {
  1431. log.Error(4, "GitFsck: %v", err)
  1432. }
  1433. }
  1434. func GitGcRepos() error {
  1435. args := append([]string{"gc"}, setting.Git.GCArgs...)
  1436. return x.
  1437. Where("id > 0").
  1438. Iterate(new(Repository),
  1439. func(idx int, bean interface{}) error {
  1440. repo := bean.(*Repository)
  1441. if err := repo.GetOwner(); err != nil {
  1442. return err
  1443. }
  1444. _, stderr, err := process.ExecDir(
  1445. time.Duration(setting.Git.Timeout.GC)*time.Second,
  1446. RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection",
  1447. "git", args...)
  1448. if err != nil {
  1449. return fmt.Errorf("%v: %v", err, stderr)
  1450. }
  1451. return nil
  1452. })
  1453. }
  1454. type repoChecker struct {
  1455. querySQL, correctSQL string
  1456. desc string
  1457. }
  1458. func repoStatsCheck(checker *repoChecker) {
  1459. results, err := x.Query(checker.querySQL)
  1460. if err != nil {
  1461. log.Error(4, "Select %s: %v", checker.desc, err)
  1462. return
  1463. }
  1464. for _, result := range results {
  1465. id := com.StrTo(result["id"]).MustInt64()
  1466. log.Trace("Updating %s: %d", checker.desc, id)
  1467. _, err = x.Exec(checker.correctSQL, id, id)
  1468. if err != nil {
  1469. log.Error(4, "Update %s[%d]: %v", checker.desc, id, err)
  1470. }
  1471. }
  1472. }
  1473. func CheckRepoStats() {
  1474. if taskStatusTable.IsRunning(checkRepos) {
  1475. return
  1476. }
  1477. taskStatusTable.Start(checkRepos)
  1478. defer taskStatusTable.Stop(checkRepos)
  1479. log.Trace("Doing: CheckRepoStats")
  1480. checkers := []*repoChecker{
  1481. // Repository.NumWatches
  1482. {
  1483. "SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id)",
  1484. "UPDATE `repository` SET num_watches=(SELECT COUNT(*) FROM `watch` WHERE repo_id=?) WHERE id=?",
  1485. "repository count 'num_watches'",
  1486. },
  1487. // Repository.NumStars
  1488. {
  1489. "SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)",
  1490. "UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?",
  1491. "repository count 'num_stars'",
  1492. },
  1493. // Label.NumIssues
  1494. {
  1495. "SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)",
  1496. "UPDATE `label` SET num_issues=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=?) WHERE id=?",
  1497. "label count 'num_issues'",
  1498. },
  1499. // User.NumRepos
  1500. {
  1501. "SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)",
  1502. "UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?",
  1503. "user count 'num_repos'",
  1504. },
  1505. // Issue.NumComments
  1506. {
  1507. "SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND type=0)",
  1508. "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND type=0) WHERE id=?",
  1509. "issue count 'num_comments'",
  1510. },
  1511. }
  1512. for i := range checkers {
  1513. repoStatsCheck(checkers[i])
  1514. }
  1515. // ***** START: Repository.NumClosedIssues *****
  1516. desc := "repository count 'num_closed_issues'"
  1517. results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false)
  1518. if err != nil {
  1519. log.Error(4, "Select %s: %v", desc, err)
  1520. } else {
  1521. for _, result := range results {
  1522. id := com.StrTo(result["id"]).MustInt64()
  1523. log.Trace("Updating %s: %d", desc, id)
  1524. _, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id)
  1525. if err != nil {
  1526. log.Error(4, "Update %s[%d]: %v", desc, id, err)
  1527. }
  1528. }
  1529. }
  1530. // ***** END: Repository.NumClosedIssues *****
  1531. // FIXME: use checker when stop supporting old fork repo format.
  1532. // ***** START: Repository.NumForks *****
  1533. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
  1534. if err != nil {
  1535. log.Error(4, "Select repository count 'num_forks': %v", err)
  1536. } else {
  1537. for _, result := range results {
  1538. id := com.StrTo(result["id"]).MustInt64()
  1539. log.Trace("Updating repository count 'num_forks': %d", id)
  1540. repo, err := GetRepositoryByID(id)
  1541. if err != nil {
  1542. log.Error(4, "GetRepositoryByID[%d]: %v", id, err)
  1543. continue
  1544. }
  1545. rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
  1546. if err != nil {
  1547. log.Error(4, "Select count of forks[%d]: %v", repo.ID, err)
  1548. continue
  1549. }
  1550. repo.NumForks = int(parseCountResult(rawResult))
  1551. if err = UpdateRepository(repo, false); err != nil {
  1552. log.Error(4, "UpdateRepository[%d]: %v", id, err)
  1553. continue
  1554. }
  1555. }
  1556. }
  1557. // ***** END: Repository.NumForks *****
  1558. }
  1559. type RepositoryList []*Repository
  1560. func (repos RepositoryList) loadAttributes(e Engine) error {
  1561. if len(repos) == 0 {
  1562. return nil
  1563. }
  1564. // Load owners.
  1565. set := make(map[int64]*User)
  1566. for i := range repos {
  1567. set[repos[i].OwnerID] = nil
  1568. }
  1569. userIDs := make([]int64, 0, len(set))
  1570. for userID := range set {
  1571. userIDs = append(userIDs, userID)
  1572. }
  1573. users := make([]*User, 0, len(userIDs))
  1574. if err := e.
  1575. Where("id > 0").
  1576. In("id", userIDs).
  1577. Find(&users); err != nil {
  1578. return fmt.Errorf("find users: %v", err)
  1579. }
  1580. for i := range users {
  1581. set[users[i].ID] = users[i]
  1582. }
  1583. for i := range repos {
  1584. repos[i].Owner = set[repos[i].OwnerID]
  1585. }
  1586. return nil
  1587. }
  1588. func (repos RepositoryList) LoadAttributes() error {
  1589. return repos.loadAttributes(x)
  1590. }
  1591. type MirrorRepositoryList []*Repository
  1592. func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
  1593. if len(repos) == 0 {
  1594. return nil
  1595. }
  1596. // Load mirrors.
  1597. repoIDs := make([]int64, 0, len(repos))
  1598. for i := range repos {
  1599. if !repos[i].IsMirror {
  1600. continue
  1601. }
  1602. repoIDs = append(repoIDs, repos[i].ID)
  1603. }
  1604. mirrors := make([]*Mirror, 0, len(repoIDs))
  1605. if err := e.
  1606. Where("id > 0").
  1607. In("repo_id", repoIDs).
  1608. Find(&mirrors); err != nil {
  1609. return fmt.Errorf("find mirrors: %v", err)
  1610. }
  1611. set := make(map[int64]*Mirror)
  1612. for i := range mirrors {
  1613. set[mirrors[i].RepoID] = mirrors[i]
  1614. }
  1615. for i := range repos {
  1616. repos[i].Mirror = set[repos[i].ID]
  1617. }
  1618. return nil
  1619. }
  1620. func (repos MirrorRepositoryList) LoadAttributes() error {
  1621. return repos.loadAttributes(x)
  1622. }
  1623. // __ __ __ .__
  1624. // / \ / \_____ _/ |_ ____ | |__
  1625. // \ \/\/ /\__ \\ __\/ ___\| | \
  1626. // \ / / __ \| | \ \___| Y \
  1627. // \__/\ / (____ /__| \___ >___| /
  1628. // \/ \/ \/ \/
  1629. // Watch is connection request for receiving repository notification.
  1630. type Watch struct {
  1631. ID int64 `xorm:"pk autoincr"`
  1632. UserID int64 `xorm:"UNIQUE(watch)"`
  1633. RepoID int64 `xorm:"UNIQUE(watch)"`
  1634. }
  1635. func isWatching(e Engine, userID, repoID int64) bool {
  1636. has, _ := e.Get(&Watch{0, userID, repoID})
  1637. return has
  1638. }
  1639. // IsWatching checks if user has watched given repository.
  1640. func IsWatching(userID, repoID int64) bool {
  1641. return isWatching(x, userID, repoID)
  1642. }
  1643. func watchRepo(e Engine, userID, repoID int64, watch bool) (err error) {
  1644. if watch {
  1645. if isWatching(e, userID, repoID) {
  1646. return nil
  1647. }
  1648. if _, err = e.Insert(&Watch{RepoID: repoID, UserID: userID}); err != nil {
  1649. return err
  1650. }
  1651. _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoID)
  1652. } else {
  1653. if !isWatching(e, userID, repoID) {
  1654. return nil
  1655. }
  1656. if _, err = e.Delete(&Watch{0, userID, repoID}); err != nil {
  1657. return err
  1658. }
  1659. _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoID)
  1660. }
  1661. return err
  1662. }
  1663. // Watch or unwatch repository.
  1664. func WatchRepo(userID, repoID int64, watch bool) (err error) {
  1665. return watchRepo(x, userID, repoID, watch)
  1666. }
  1667. func getWatchers(e Engine, repoID int64) ([]*Watch, error) {
  1668. watches := make([]*Watch, 0, 10)
  1669. return watches, e.Find(&watches, &Watch{RepoID: repoID})
  1670. }
  1671. // GetWatchers returns all watchers of given repository.
  1672. func GetWatchers(repoID int64) ([]*Watch, error) {
  1673. return getWatchers(x, repoID)
  1674. }
  1675. // Repository.GetWatchers returns range of users watching given repository.
  1676. func (repo *Repository) GetWatchers(page int) ([]*User, error) {
  1677. users := make([]*User, 0, ItemsPerPage)
  1678. sess := x.
  1679. Limit(ItemsPerPage, (page-1)*ItemsPerPage).
  1680. Where("watch.repo_id=?", repo.ID)
  1681. if setting.UsePostgreSQL {
  1682. sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`)
  1683. } else {
  1684. sess = sess.Join("LEFT", "watch", "user.id=watch.user_id")
  1685. }
  1686. return users, sess.Find(&users)
  1687. }
  1688. func notifyWatchers(e Engine, act *Action) error {
  1689. // Add feeds for user self and all watchers.
  1690. watches, err := getWatchers(e, act.RepoID)
  1691. if err != nil {
  1692. return fmt.Errorf("get watchers: %v", err)
  1693. }
  1694. // Add feed for actioner.
  1695. act.UserID = act.ActUserID
  1696. if _, err = e.InsertOne(act); err != nil {
  1697. return fmt.Errorf("insert new actioner: %v", err)
  1698. }
  1699. for i := range watches {
  1700. if act.ActUserID == watches[i].UserID {
  1701. continue
  1702. }
  1703. act.ID = 0
  1704. act.UserID = watches[i].UserID
  1705. if _, err = e.InsertOne(act); err != nil {
  1706. return fmt.Errorf("insert new action: %v", err)
  1707. }
  1708. }
  1709. return nil
  1710. }
  1711. // NotifyWatchers creates batch of actions for every watcher.
  1712. func NotifyWatchers(act *Action) error {
  1713. return notifyWatchers(x, act)
  1714. }
  1715. // _________ __
  1716. // / _____// |______ _______
  1717. // \_____ \\ __\__ \\_ __ \
  1718. // / \| | / __ \| | \/
  1719. // /_______ /|__| (____ /__|
  1720. // \/ \/
  1721. type Star struct {
  1722. ID int64 `xorm:"pk autoincr"`
  1723. UID int64 `xorm:"UNIQUE(s)"`
  1724. RepoID int64 `xorm:"UNIQUE(s)"`
  1725. }
  1726. // Star or unstar repository.
  1727. func StarRepo(userID, repoID int64, star bool) (err error) {
  1728. if star {
  1729. if IsStaring(userID, repoID) {
  1730. return nil
  1731. }
  1732. if _, err = x.Insert(&Star{UID: userID, RepoID: repoID}); err != nil {
  1733. return err
  1734. } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoID); err != nil {
  1735. return err
  1736. }
  1737. _, err = x.Exec("UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", userID)
  1738. } else {
  1739. if !IsStaring(userID, repoID) {
  1740. return nil
  1741. }
  1742. if _, err = x.Delete(&Star{0, userID, repoID}); err != nil {
  1743. return err
  1744. } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoID); err != nil {
  1745. return err
  1746. }
  1747. _, err = x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID)
  1748. }
  1749. return err
  1750. }
  1751. // IsStaring checks if user has starred given repository.
  1752. func IsStaring(userID, repoID int64) bool {
  1753. has, _ := x.Get(&Star{0, userID, repoID})
  1754. return has
  1755. }
  1756. func (repo *Repository) GetStargazers(page int) ([]*User, error) {
  1757. users := make([]*User, 0, ItemsPerPage)
  1758. sess := x.
  1759. Limit(ItemsPerPage, (page-1)*ItemsPerPage).
  1760. Where("star.repo_id=?", repo.ID)
  1761. if setting.UsePostgreSQL {
  1762. sess = sess.Join("LEFT", "star", `"user".id=star.uid`)
  1763. } else {
  1764. sess = sess.Join("LEFT", "star", "user.id=star.uid")
  1765. }
  1766. return users, sess.Find(&users)
  1767. }
  1768. // ___________ __
  1769. // \_ _____/__________| | __
  1770. // | __)/ _ \_ __ \ |/ /
  1771. // | \( <_> ) | \/ <
  1772. // \___ / \____/|__| |__|_ \
  1773. // \/ \/
  1774. // HasForkedRepo checks if given user has already forked a repository with given ID.
  1775. func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
  1776. repo := new(Repository)
  1777. has, _ := x.
  1778. Where("owner_id=? AND fork_id=?", ownerID, repoID).
  1779. Get(repo)
  1780. return repo, has
  1781. }
  1782. func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
  1783. repo := &Repository{
  1784. OwnerID: u.ID,
  1785. Owner: u,
  1786. Name: name,
  1787. LowerName: strings.ToLower(name),
  1788. Description: desc,
  1789. DefaultBranch: oldRepo.DefaultBranch,
  1790. IsPrivate: oldRepo.IsPrivate,
  1791. IsFork: true,
  1792. ForkID: oldRepo.ID,
  1793. }
  1794. sess := x.NewSession()
  1795. defer sessionRelease(sess)
  1796. if err = sess.Begin(); err != nil {
  1797. return nil, err
  1798. }
  1799. if err = createRepository(sess, u, repo); err != nil {
  1800. return nil, err
  1801. }
  1802. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
  1803. return nil, err
  1804. }
  1805. repoPath := RepoPath(u.Name, repo.Name)
  1806. _, stderr, err := process.ExecTimeout(10*time.Minute,
  1807. fmt.Sprintf("ForkRepository(git clone): %s/%s", u.Name, repo.Name),
  1808. "git", "clone", "--bare", oldRepo.RepoPath(), repoPath)
  1809. if err != nil {
  1810. return nil, fmt.Errorf("git clone: %v", stderr)
  1811. }
  1812. _, stderr, err = process.ExecDir(-1,
  1813. repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath),
  1814. "git", "update-server-info")
  1815. if err != nil {
  1816. return nil, fmt.Errorf("git update-server-info: %v", stderr)
  1817. }
  1818. if err = createUpdateHook(repoPath); err != nil {
  1819. return nil, fmt.Errorf("createUpdateHook: %v", err)
  1820. }
  1821. return repo, sess.Commit()
  1822. }
  1823. func (repo *Repository) GetForks() ([]*Repository, error) {
  1824. forks := make([]*Repository, 0, repo.NumForks)
  1825. return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
  1826. }
  1827. // __________ .__
  1828. // \______ \____________ ____ ____ | |__
  1829. // | | _/\_ __ \__ \ / \_/ ___\| | \
  1830. // | | \ | | \// __ \| | \ \___| Y \
  1831. // |______ / |__| (____ /___| /\___ >___| /
  1832. // \/ \/ \/ \/ \/
  1833. //
  1834. func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
  1835. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  1836. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  1837. localPath := repo.LocalCopyPath()
  1838. if err = discardLocalRepoBranchChanges(localPath, oldBranchName); err != nil {
  1839. return fmt.Errorf("discardLocalRepoChanges: %v", err)
  1840. } else if err = repo.UpdateLocalCopyBranch(oldBranchName); err != nil {
  1841. return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
  1842. }
  1843. if err = repo.CheckoutNewBranch(oldBranchName, branchName); err != nil {
  1844. return fmt.Errorf("CreateNewBranch: %v", err)
  1845. }
  1846. if err = git.Push(localPath, "origin", branchName); err != nil {
  1847. return fmt.Errorf("Push: %v", err)
  1848. }
  1849. return nil
  1850. }