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

repo.go 65 kB

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