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 60KB

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