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 72 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
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 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
11 years ago
8 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
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
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 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
10 years ago
10 years ago
9 years ago
9 years ago
9 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
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
9 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 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
9 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
11 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package models
  6. import (
  7. "bytes"
  8. "errors"
  9. "fmt"
  10. "html/template"
  11. "io/ioutil"
  12. "os"
  13. "os/exec"
  14. "path"
  15. "path/filepath"
  16. "regexp"
  17. "sort"
  18. "strings"
  19. "time"
  20. "code.gitea.io/git"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/markdown"
  23. "code.gitea.io/gitea/modules/options"
  24. "code.gitea.io/gitea/modules/process"
  25. "code.gitea.io/gitea/modules/setting"
  26. "code.gitea.io/gitea/modules/sync"
  27. api "code.gitea.io/sdk/gitea"
  28. "github.com/Unknwon/cae/zip"
  29. "github.com/Unknwon/com"
  30. "github.com/go-xorm/xorm"
  31. "github.com/mcuadros/go-version"
  32. "gopkg.in/ini.v1"
  33. )
  34. const (
  35. tplUpdateHook = "#!/usr/bin/env %s\n%s update $1 $2 $3 --config='%s'\n"
  36. )
  37. var repoWorkingPool = sync.NewExclusivePool()
  38. var (
  39. // ErrRepoFileNotExist repository file does not exist error
  40. ErrRepoFileNotExist = errors.New("Repository file does not exist")
  41. // ErrRepoFileNotLoaded repository file not loaded error
  42. ErrRepoFileNotLoaded = errors.New("Repository file not loaded")
  43. // ErrMirrorNotExist mirror does not exist error
  44. ErrMirrorNotExist = errors.New("Mirror does not exist")
  45. // ErrInvalidReference invalid reference specified error
  46. ErrInvalidReference = errors.New("Invalid reference specified")
  47. // ErrNameEmpty name is empty error
  48. ErrNameEmpty = errors.New("Name is empty")
  49. )
  50. var (
  51. // Gitignores contains the gitiginore files
  52. Gitignores []string
  53. // Licenses contains the license files
  54. Licenses []string
  55. // Readmes contains the readme files
  56. Readmes []string
  57. // LabelTemplates contains the label template files
  58. LabelTemplates []string
  59. // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
  60. ItemsPerPage = 40
  61. )
  62. // LoadRepoConfig loads the repository config
  63. func LoadRepoConfig() {
  64. // Load .gitignore and license files and readme templates.
  65. types := []string{"gitignore", "license", "readme", "label"}
  66. typeFiles := make([][]string, 4)
  67. for i, t := range types {
  68. files, err := options.Dir(t)
  69. if err != nil {
  70. log.Fatal(4, "Failed to get %s files: %v", t, err)
  71. }
  72. customPath := path.Join(setting.CustomPath, "options", t)
  73. if com.IsDir(customPath) {
  74. customFiles, err := com.StatDir(customPath)
  75. if err != nil {
  76. log.Fatal(4, "Failed to get custom %s files: %v", t, err)
  77. }
  78. for _, f := range customFiles {
  79. if !com.IsSliceContainsStr(files, f) {
  80. files = append(files, f)
  81. }
  82. }
  83. }
  84. typeFiles[i] = files
  85. }
  86. Gitignores = typeFiles[0]
  87. Licenses = typeFiles[1]
  88. Readmes = typeFiles[2]
  89. LabelTemplates = typeFiles[3]
  90. sort.Strings(Gitignores)
  91. sort.Strings(Licenses)
  92. sort.Strings(Readmes)
  93. sort.Strings(LabelTemplates)
  94. // Filter out invalid names and promote preferred licenses.
  95. sortedLicenses := make([]string, 0, len(Licenses))
  96. for _, name := range setting.Repository.PreferredLicenses {
  97. if com.IsSliceContainsStr(Licenses, name) {
  98. sortedLicenses = append(sortedLicenses, name)
  99. }
  100. }
  101. for _, name := range Licenses {
  102. if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
  103. sortedLicenses = append(sortedLicenses, name)
  104. }
  105. }
  106. Licenses = sortedLicenses
  107. }
  108. // NewRepoContext creates a new repository context
  109. func NewRepoContext() {
  110. zip.Verbose = false
  111. // Check Git installation.
  112. if _, err := exec.LookPath("git"); err != nil {
  113. log.Fatal(4, "Failed to test 'git' command: %v (forgotten install?)", err)
  114. }
  115. // Check Git version.
  116. var err error
  117. setting.Git.Version, err = git.BinVersion()
  118. if err != nil {
  119. log.Fatal(4, "Failed to get Git version: %v", err)
  120. }
  121. log.Info("Git Version: %s", setting.Git.Version)
  122. if version.Compare("1.7.1", setting.Git.Version, ">") {
  123. log.Fatal(4, "Gitea requires Git version greater or equal to 1.7.1")
  124. }
  125. // Git requires setting user.name and user.email in order to commit changes.
  126. for configKey, defaultValue := range map[string]string{"user.name": "Gitea", "user.email": "gitea@fake.local"} {
  127. if stdout, stderr, err := process.GetManager().Exec("NewRepoContext(get setting)", "git", "config", "--get", configKey); err != nil || strings.TrimSpace(stdout) == "" {
  128. // ExitError indicates this config is not set
  129. if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
  130. if _, stderr, gerr := process.GetManager().Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
  131. log.Fatal(4, "Failed to set git %s(%s): %s", configKey, gerr, stderr)
  132. }
  133. log.Info("Git config %s set to %s", configKey, defaultValue)
  134. } else {
  135. log.Fatal(4, "Failed to get git %s(%s): %s", configKey, err, stderr)
  136. }
  137. }
  138. }
  139. // Set git some configurations.
  140. if _, stderr, err := process.GetManager().Exec("NewRepoContext(git config --global core.quotepath false)",
  141. "git", "config", "--global", "core.quotepath", "false"); err != nil {
  142. log.Fatal(4, "Failed to execute 'git config --global core.quotepath false': %s", stderr)
  143. }
  144. RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
  145. }
  146. // Repository represents a git repository.
  147. type Repository struct {
  148. ID int64 `xorm:"pk autoincr"`
  149. OwnerID int64 `xorm:"UNIQUE(s)"`
  150. Owner *User `xorm:"-"`
  151. LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
  152. Name string `xorm:"INDEX NOT NULL"`
  153. Description string
  154. Website string
  155. DefaultBranch string
  156. NumWatches int
  157. NumStars int
  158. NumForks int
  159. NumIssues int
  160. NumClosedIssues int
  161. NumOpenIssues int `xorm:"-"`
  162. NumPulls int
  163. NumClosedPulls int
  164. NumOpenPulls int `xorm:"-"`
  165. NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
  166. NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
  167. NumOpenMilestones int `xorm:"-"`
  168. NumReleases int `xorm:"-"`
  169. IsPrivate bool `xorm:"INDEX"`
  170. IsBare bool `xorm:"INDEX"`
  171. IsMirror bool `xorm:"INDEX"`
  172. *Mirror `xorm:"-"`
  173. ExternalMetas map[string]string `xorm:"-"`
  174. Units []*RepoUnit `xorm:"-"`
  175. IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
  176. ForkID int64 `xorm:"INDEX"`
  177. BaseRepo *Repository `xorm:"-"`
  178. Size int64 `xorm:"NOT NULL DEFAULT 0"`
  179. Created time.Time `xorm:"-"`
  180. CreatedUnix int64 `xorm:"INDEX created"`
  181. Updated time.Time `xorm:"-"`
  182. UpdatedUnix int64 `xorm:"INDEX updated"`
  183. }
  184. // AfterSet is invoked from XORM after setting the value of a field of this object.
  185. func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
  186. switch colName {
  187. case "default_branch":
  188. // FIXME: use models migration to solve all at once.
  189. if len(repo.DefaultBranch) == 0 {
  190. repo.DefaultBranch = "master"
  191. }
  192. case "num_closed_issues":
  193. repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
  194. case "num_closed_pulls":
  195. repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
  196. case "num_closed_milestones":
  197. repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
  198. case "created_unix":
  199. repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
  200. case "updated_unix":
  201. repo.Updated = time.Unix(repo.UpdatedUnix, 0)
  202. }
  203. }
  204. // MustOwner always returns a valid *User object to avoid
  205. // conceptually impossible error handling.
  206. // It creates a fake object that contains error details
  207. // when error occurs.
  208. func (repo *Repository) MustOwner() *User {
  209. return repo.mustOwner(x)
  210. }
  211. // FullName returns the repository full name
  212. func (repo *Repository) FullName() string {
  213. return repo.MustOwner().Name + "/" + repo.Name
  214. }
  215. // HTMLURL returns the repository HTML URL
  216. func (repo *Repository) HTMLURL() string {
  217. return setting.AppURL + repo.FullName()
  218. }
  219. // APIURL returns the repository API URL
  220. func (repo *Repository) APIURL() string {
  221. return setting.AppURL + path.Join("api/v1/repos", repo.FullName())
  222. }
  223. // APIFormat converts a Repository to api.Repository
  224. func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
  225. return repo.innerAPIFormat(mode, false)
  226. }
  227. func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repository {
  228. var parent *api.Repository
  229. cloneLink := repo.CloneLink()
  230. permission := &api.Permission{
  231. Admin: mode >= AccessModeAdmin,
  232. Push: mode >= AccessModeWrite,
  233. Pull: mode >= AccessModeRead,
  234. }
  235. if !isParent {
  236. err := repo.GetBaseRepo()
  237. if err != nil {
  238. log.Error(4, "APIFormat: %v", err)
  239. }
  240. if repo.BaseRepo != nil {
  241. parent = repo.BaseRepo.innerAPIFormat(mode, true)
  242. }
  243. }
  244. return &api.Repository{
  245. ID: repo.ID,
  246. Owner: repo.Owner.APIFormat(),
  247. Name: repo.Name,
  248. FullName: repo.FullName(),
  249. Description: repo.Description,
  250. Private: repo.IsPrivate,
  251. Empty: repo.IsBare,
  252. Size: int(repo.Size / 1024),
  253. Fork: repo.IsFork,
  254. Parent: parent,
  255. Mirror: repo.IsMirror,
  256. HTMLURL: repo.HTMLURL(),
  257. SSHURL: cloneLink.SSH,
  258. CloneURL: cloneLink.HTTPS,
  259. Website: repo.Website,
  260. Stars: repo.NumStars,
  261. Forks: repo.NumForks,
  262. Watchers: repo.NumWatches,
  263. OpenIssues: repo.NumOpenIssues,
  264. DefaultBranch: repo.DefaultBranch,
  265. Created: repo.Created,
  266. Updated: repo.Updated,
  267. Permissions: permission,
  268. }
  269. }
  270. func (repo *Repository) getUnits(e Engine) (err error) {
  271. if repo.Units != nil {
  272. return nil
  273. }
  274. repo.Units, err = getUnitsByRepoID(e, repo.ID)
  275. return err
  276. }
  277. // CheckUnitUser check whether user could visit the unit of this repository
  278. func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool {
  279. if err := repo.getUnitsByUserID(x, userID, isAdmin); err != nil {
  280. return false
  281. }
  282. for _, unit := range repo.Units {
  283. if unit.Type == unitType {
  284. return true
  285. }
  286. }
  287. return false
  288. }
  289. // LoadUnitsByUserID loads units according userID's permissions
  290. func (repo *Repository) LoadUnitsByUserID(userID int64, isAdmin bool) error {
  291. return repo.getUnitsByUserID(x, userID, isAdmin)
  292. }
  293. func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (err error) {
  294. if repo.Units != nil {
  295. return nil
  296. }
  297. if err = repo.getUnits(e); err != nil {
  298. return err
  299. } else if err = repo.getOwner(e); err != nil {
  300. return err
  301. }
  302. if !repo.Owner.IsOrganization() || userID == 0 || isAdmin || !repo.IsPrivate {
  303. return nil
  304. }
  305. // Collaborators will not be limited
  306. if isCollaborator, err := repo.isCollaborator(e, userID); err != nil {
  307. return err
  308. } else if isCollaborator {
  309. return nil
  310. }
  311. teams, err := getUserTeams(e, repo.OwnerID, userID)
  312. if err != nil {
  313. return err
  314. }
  315. var allTypes = make(map[UnitType]struct{}, len(allRepUnitTypes))
  316. for _, team := range teams {
  317. // Administrators can not be limited
  318. if team.Authorize >= AccessModeAdmin {
  319. return nil
  320. }
  321. for _, unitType := range team.UnitTypes {
  322. allTypes[unitType] = struct{}{}
  323. }
  324. }
  325. // unique
  326. var newRepoUnits = make([]*RepoUnit, 0, len(repo.Units))
  327. for _, u := range repo.Units {
  328. if _, ok := allTypes[u.Type]; ok {
  329. newRepoUnits = append(newRepoUnits, u)
  330. }
  331. }
  332. repo.Units = newRepoUnits
  333. return nil
  334. }
  335. // UnitEnabled if this repository has the given unit enabled
  336. func (repo *Repository) UnitEnabled(tp UnitType) bool {
  337. repo.getUnits(x)
  338. for _, unit := range repo.Units {
  339. if unit.Type == tp {
  340. return true
  341. }
  342. }
  343. return false
  344. }
  345. var (
  346. // ErrUnitNotExist organization does not exist
  347. ErrUnitNotExist = errors.New("Unit does not exist")
  348. )
  349. // MustGetUnit always returns a RepoUnit object
  350. func (repo *Repository) MustGetUnit(tp UnitType) *RepoUnit {
  351. ru, err := repo.GetUnit(tp)
  352. if err == nil {
  353. return ru
  354. }
  355. if tp == UnitTypeExternalWiki {
  356. return &RepoUnit{
  357. Type: tp,
  358. Config: new(ExternalWikiConfig),
  359. }
  360. } else if tp == UnitTypeExternalTracker {
  361. return &RepoUnit{
  362. Type: tp,
  363. Config: new(ExternalTrackerConfig),
  364. }
  365. }
  366. return &RepoUnit{
  367. Type: tp,
  368. Config: new(UnitConfig),
  369. }
  370. }
  371. // GetUnit returns a RepoUnit object
  372. func (repo *Repository) GetUnit(tp UnitType) (*RepoUnit, error) {
  373. if err := repo.getUnits(x); err != nil {
  374. return nil, err
  375. }
  376. for _, unit := range repo.Units {
  377. if unit.Type == tp {
  378. return unit, nil
  379. }
  380. }
  381. return nil, ErrUnitNotExist
  382. }
  383. func (repo *Repository) getOwner(e Engine) (err error) {
  384. if repo.Owner != nil {
  385. return nil
  386. }
  387. repo.Owner, err = getUserByID(e, repo.OwnerID)
  388. return err
  389. }
  390. // GetOwner returns the repository owner
  391. func (repo *Repository) GetOwner() error {
  392. return repo.getOwner(x)
  393. }
  394. func (repo *Repository) mustOwner(e Engine) *User {
  395. if err := repo.getOwner(e); err != nil {
  396. return &User{
  397. Name: "error",
  398. FullName: err.Error(),
  399. }
  400. }
  401. return repo.Owner
  402. }
  403. // ComposeMetas composes a map of metas for rendering external issue tracker URL.
  404. func (repo *Repository) ComposeMetas() map[string]string {
  405. unit, err := repo.GetUnit(UnitTypeExternalTracker)
  406. if err != nil {
  407. return nil
  408. }
  409. if repo.ExternalMetas == nil {
  410. repo.ExternalMetas = map[string]string{
  411. "format": unit.ExternalTrackerConfig().ExternalTrackerFormat,
  412. "user": repo.MustOwner().Name,
  413. "repo": repo.Name,
  414. }
  415. switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
  416. case markdown.IssueNameStyleAlphanumeric:
  417. repo.ExternalMetas["style"] = markdown.IssueNameStyleAlphanumeric
  418. default:
  419. repo.ExternalMetas["style"] = markdown.IssueNameStyleNumeric
  420. }
  421. }
  422. return repo.ExternalMetas
  423. }
  424. // DeleteWiki removes the actual and local copy of repository wiki.
  425. func (repo *Repository) DeleteWiki() error {
  426. return repo.deleteWiki(x)
  427. }
  428. func (repo *Repository) deleteWiki(e Engine) error {
  429. wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
  430. for _, wikiPath := range wikiPaths {
  431. removeAllWithNotice(e, "Delete repository wiki", wikiPath)
  432. }
  433. _, err := e.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeWiki).Delete(new(RepoUnit))
  434. return err
  435. }
  436. func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
  437. if err = repo.getOwner(e); err != nil {
  438. return nil, err
  439. }
  440. accesses := make([]*Access, 0, 10)
  441. if err = e.
  442. Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite).
  443. Find(&accesses); err != nil {
  444. return nil, err
  445. }
  446. // Leave a seat for owner itself to append later, but if owner is an organization
  447. // and just waste 1 unit is cheaper than re-allocate memory once.
  448. users := make([]*User, 0, len(accesses)+1)
  449. if len(accesses) > 0 {
  450. userIDs := make([]int64, len(accesses))
  451. for i := 0; i < len(accesses); i++ {
  452. userIDs[i] = accesses[i].UserID
  453. }
  454. if err = e.In("id", userIDs).Find(&users); err != nil {
  455. return nil, err
  456. }
  457. }
  458. if !repo.Owner.IsOrganization() {
  459. users = append(users, repo.Owner)
  460. }
  461. return users, nil
  462. }
  463. // GetAssignees returns all users that have write access and can be assigned to issues
  464. // of the repository,
  465. func (repo *Repository) GetAssignees() (_ []*User, err error) {
  466. return repo.getAssignees(x)
  467. }
  468. // GetAssigneeByID returns the user that has write access of repository by given ID.
  469. func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) {
  470. return GetAssigneeByID(repo, userID)
  471. }
  472. // GetMilestoneByID returns the milestone belongs to repository by given ID.
  473. func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
  474. return GetMilestoneByRepoID(repo.ID, milestoneID)
  475. }
  476. // IssueStats returns number of open and closed repository issues by given filter mode.
  477. func (repo *Repository) IssueStats(uid int64, filterMode int, isPull bool) (int64, int64) {
  478. return GetRepoIssueStats(repo.ID, uid, filterMode, isPull)
  479. }
  480. // GetMirror sets the repository mirror, returns an error upon failure
  481. func (repo *Repository) GetMirror() (err error) {
  482. repo.Mirror, err = GetMirrorByRepoID(repo.ID)
  483. return err
  484. }
  485. // GetBaseRepo returns the base repository
  486. func (repo *Repository) GetBaseRepo() (err error) {
  487. if !repo.IsFork {
  488. return nil
  489. }
  490. repo.BaseRepo, err = GetRepositoryByID(repo.ForkID)
  491. return err
  492. }
  493. func (repo *Repository) repoPath(e Engine) string {
  494. return RepoPath(repo.mustOwner(e).Name, repo.Name)
  495. }
  496. // RepoPath returns the repository path
  497. func (repo *Repository) RepoPath() string {
  498. return repo.repoPath(x)
  499. }
  500. // GitConfigPath returns the repository git config path
  501. func (repo *Repository) GitConfigPath() string {
  502. return filepath.Join(repo.RepoPath(), "config")
  503. }
  504. // RelLink returns the repository relative link
  505. func (repo *Repository) RelLink() string {
  506. return "/" + repo.FullName()
  507. }
  508. // Link returns the repository link
  509. func (repo *Repository) Link() string {
  510. return setting.AppSubURL + "/" + repo.FullName()
  511. }
  512. // ComposeCompareURL returns the repository comparison URL
  513. func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string {
  514. return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
  515. }
  516. // HasAccess returns true when user has access to this repository
  517. func (repo *Repository) HasAccess(u *User) bool {
  518. has, _ := HasAccess(u.ID, repo, AccessModeRead)
  519. return has
  520. }
  521. // UpdateDefaultBranch updates the default branch
  522. func (repo *Repository) UpdateDefaultBranch() error {
  523. _, err := x.ID(repo.ID).Cols("default_branch").Update(repo)
  524. return err
  525. }
  526. // IsOwnedBy returns true when user owns this repository
  527. func (repo *Repository) IsOwnedBy(userID int64) bool {
  528. return repo.OwnerID == userID
  529. }
  530. func (repo *Repository) updateSize(e Engine) error {
  531. repoInfoSize, err := git.GetRepoSize(repo.RepoPath())
  532. if err != nil {
  533. return fmt.Errorf("UpdateSize: %v", err)
  534. }
  535. repo.Size = repoInfoSize.Size + repoInfoSize.SizePack
  536. _, err = e.Id(repo.ID).Cols("size").Update(repo)
  537. return err
  538. }
  539. // UpdateSize updates the repository size, calculating it using git.GetRepoSize
  540. func (repo *Repository) UpdateSize() error {
  541. return repo.updateSize(x)
  542. }
  543. // CanBeForked returns true if repository meets the requirements of being forked.
  544. func (repo *Repository) CanBeForked() bool {
  545. return !repo.IsBare
  546. }
  547. // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
  548. func (repo *Repository) CanEnablePulls() bool {
  549. return !repo.IsMirror && !repo.IsBare
  550. }
  551. // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
  552. func (repo *Repository) AllowsPulls() bool {
  553. return repo.CanEnablePulls() && repo.UnitEnabled(UnitTypePullRequests)
  554. }
  555. // CanEnableEditor returns true if repository meets the requirements of web editor.
  556. func (repo *Repository) CanEnableEditor() bool {
  557. return !repo.IsMirror
  558. }
  559. // GetWriters returns all users that have write access to the repository.
  560. func (repo *Repository) GetWriters() (_ []*User, err error) {
  561. return repo.getUsersWithAccessMode(x, AccessModeWrite)
  562. }
  563. // getUsersWithAccessMode returns users that have at least given access mode to the repository.
  564. func (repo *Repository) getUsersWithAccessMode(e Engine, mode AccessMode) (_ []*User, err error) {
  565. if err = repo.getOwner(e); err != nil {
  566. return nil, err
  567. }
  568. accesses := make([]*Access, 0, 10)
  569. if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, mode).Find(&accesses); err != nil {
  570. return nil, err
  571. }
  572. // Leave a seat for owner itself to append later, but if owner is an organization
  573. // and just waste 1 unit is cheaper than re-allocate memory once.
  574. users := make([]*User, 0, len(accesses)+1)
  575. if len(accesses) > 0 {
  576. userIDs := make([]int64, len(accesses))
  577. for i := 0; i < len(accesses); i++ {
  578. userIDs[i] = accesses[i].UserID
  579. }
  580. if err = e.In("id", userIDs).Find(&users); err != nil {
  581. return nil, err
  582. }
  583. }
  584. if !repo.Owner.IsOrganization() {
  585. users = append(users, repo.Owner)
  586. }
  587. return users, nil
  588. }
  589. // NextIssueIndex returns the next issue index
  590. // FIXME: should have a mutex to prevent producing same index for two issues that are created
  591. // closely enough.
  592. func (repo *Repository) NextIssueIndex() int64 {
  593. return int64(repo.NumIssues+repo.NumPulls) + 1
  594. }
  595. var (
  596. descPattern = regexp.MustCompile(`https?://\S+`)
  597. )
  598. // DescriptionHTML does special handles to description and return HTML string.
  599. func (repo *Repository) DescriptionHTML() template.HTML {
  600. sanitize := func(s string) string {
  601. return fmt.Sprintf(`<a href="%[1]s" target="_blank" rel="noopener">%[1]s</a>`, s)
  602. }
  603. return template.HTML(descPattern.ReplaceAllStringFunc(markdown.Sanitize(repo.Description), sanitize))
  604. }
  605. // LocalCopyPath returns the local repository copy path
  606. func (repo *Repository) LocalCopyPath() string {
  607. if filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
  608. return path.Join(setting.Repository.Local.LocalCopyPath, com.ToStr(repo.ID))
  609. }
  610. return path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath, com.ToStr(repo.ID))
  611. }
  612. // UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
  613. // It creates a new clone if local copy does not exist.
  614. // This function checks out target branch by default, it is safe to assume subsequent
  615. // operations are operating against target branch when caller has confidence for no race condition.
  616. func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
  617. if !com.IsExist(localPath) {
  618. if err := git.Clone(repoPath, localPath, git.CloneRepoOptions{
  619. Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
  620. Branch: branch,
  621. }); err != nil {
  622. return fmt.Errorf("git clone %s: %v", branch, err)
  623. }
  624. } else {
  625. if err := git.Checkout(localPath, git.CheckoutOptions{
  626. Branch: branch,
  627. }); err != nil {
  628. return fmt.Errorf("git checkout %s: %v", branch, err)
  629. }
  630. _, err := git.NewCommand("fetch", "origin").RunInDir(localPath)
  631. if err != nil {
  632. return fmt.Errorf("git fetch origin: %v", err)
  633. }
  634. if err := git.ResetHEAD(localPath, true, "origin/"+branch); err != nil {
  635. return fmt.Errorf("git reset --hard origin/%s: %v", branch, err)
  636. }
  637. }
  638. return nil
  639. }
  640. // UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
  641. func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
  642. return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
  643. }
  644. // PatchPath returns corresponding patch file path of repository by given issue ID.
  645. func (repo *Repository) PatchPath(index int64) (string, error) {
  646. if err := repo.GetOwner(); err != nil {
  647. return "", err
  648. }
  649. return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil
  650. }
  651. // SavePatch saves patch data to corresponding location by given issue ID.
  652. func (repo *Repository) SavePatch(index int64, patch []byte) error {
  653. patchPath, err := repo.PatchPath(index)
  654. if err != nil {
  655. return fmt.Errorf("PatchPath: %v", err)
  656. }
  657. dir := filepath.Dir(patchPath)
  658. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  659. return fmt.Errorf("Failed to create dir %s: %v", dir, err)
  660. }
  661. if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil {
  662. return fmt.Errorf("WriteFile: %v", err)
  663. }
  664. return nil
  665. }
  666. func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
  667. has, err := e.Get(&Repository{
  668. OwnerID: u.ID,
  669. LowerName: strings.ToLower(repoName),
  670. })
  671. return has && com.IsDir(RepoPath(u.Name, repoName)), err
  672. }
  673. // IsRepositoryExist returns true if the repository with given name under user has already existed.
  674. func IsRepositoryExist(u *User, repoName string) (bool, error) {
  675. return isRepositoryExist(x, u, repoName)
  676. }
  677. // CloneLink represents different types of clone URLs of repository.
  678. type CloneLink struct {
  679. SSH string
  680. HTTPS string
  681. Git string
  682. }
  683. // ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
  684. func ComposeHTTPSCloneURL(owner, repo string) string {
  685. return fmt.Sprintf("%s%s/%s.git", setting.AppURL, owner, repo)
  686. }
  687. func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
  688. repoName := repo.Name
  689. if isWiki {
  690. repoName += ".wiki"
  691. }
  692. repo.Owner = repo.MustOwner()
  693. cl := new(CloneLink)
  694. if setting.SSH.Port != 22 {
  695. cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
  696. } else if setting.Repository.UseCompatSSHURI {
  697. cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  698. } else {
  699. cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  700. }
  701. cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repoName)
  702. return cl
  703. }
  704. // CloneLink returns clone URLs of repository.
  705. func (repo *Repository) CloneLink() (cl *CloneLink) {
  706. return repo.cloneLink(false)
  707. }
  708. // MigrateRepoOptions contains the repository migrate options
  709. type MigrateRepoOptions struct {
  710. Name string
  711. Description string
  712. IsPrivate bool
  713. IsMirror bool
  714. RemoteAddr string
  715. }
  716. /*
  717. GitHub, GitLab, Gogs: *.wiki.git
  718. BitBucket: *.git/wiki
  719. */
  720. var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
  721. // wikiRemoteURL returns accessible repository URL for wiki if exists.
  722. // Otherwise, it returns an empty string.
  723. func wikiRemoteURL(remote string) string {
  724. remote = strings.TrimSuffix(remote, ".git")
  725. for _, suffix := range commonWikiURLSuffixes {
  726. wikiURL := remote + suffix
  727. if git.IsRepoURLAccessible(wikiURL) {
  728. return wikiURL
  729. }
  730. }
  731. return ""
  732. }
  733. // MigrateRepository migrates a existing repository from other project hosting.
  734. func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, error) {
  735. repo, err := CreateRepository(doer, u, CreateRepoOptions{
  736. Name: opts.Name,
  737. Description: opts.Description,
  738. IsPrivate: opts.IsPrivate,
  739. IsMirror: opts.IsMirror,
  740. })
  741. if err != nil {
  742. return nil, err
  743. }
  744. repoPath := RepoPath(u.Name, opts.Name)
  745. wikiPath := WikiPath(u.Name, opts.Name)
  746. if u.IsOrganization() {
  747. t, err := u.GetOwnerTeam()
  748. if err != nil {
  749. return nil, err
  750. }
  751. repo.NumWatches = t.NumMembers
  752. } else {
  753. repo.NumWatches = 1
  754. }
  755. migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
  756. if err := os.RemoveAll(repoPath); err != nil {
  757. return repo, fmt.Errorf("Failed to remove %s: %v", repoPath, err)
  758. }
  759. if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
  760. Mirror: true,
  761. Quiet: true,
  762. Timeout: migrateTimeout,
  763. }); err != nil {
  764. return repo, fmt.Errorf("Clone: %v", err)
  765. }
  766. wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
  767. if len(wikiRemotePath) > 0 {
  768. if err := os.RemoveAll(wikiPath); err != nil {
  769. return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
  770. }
  771. if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
  772. Mirror: true,
  773. Quiet: true,
  774. Timeout: migrateTimeout,
  775. Branch: "master",
  776. }); err != nil {
  777. log.Warn("Clone wiki: %v", err)
  778. if err := os.RemoveAll(wikiPath); err != nil {
  779. return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
  780. }
  781. }
  782. }
  783. // Check if repository is empty.
  784. _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
  785. if err != nil {
  786. if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
  787. repo.IsBare = true
  788. } else {
  789. return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
  790. }
  791. }
  792. if !repo.IsBare {
  793. // Try to get HEAD branch and set it as default branch.
  794. gitRepo, err := git.OpenRepository(repoPath)
  795. if err != nil {
  796. return repo, fmt.Errorf("OpenRepository: %v", err)
  797. }
  798. headBranch, err := gitRepo.GetHEADBranch()
  799. if err != nil {
  800. return repo, fmt.Errorf("GetHEADBranch: %v", err)
  801. }
  802. if headBranch != nil {
  803. repo.DefaultBranch = headBranch.Name
  804. }
  805. }
  806. if err = repo.UpdateSize(); err != nil {
  807. log.Error(4, "Failed to update size for repository: %v", err)
  808. }
  809. if opts.IsMirror {
  810. if _, err = x.InsertOne(&Mirror{
  811. RepoID: repo.ID,
  812. Interval: setting.Mirror.DefaultInterval,
  813. EnablePrune: true,
  814. NextUpdate: time.Now().Add(setting.Mirror.DefaultInterval),
  815. }); err != nil {
  816. return repo, fmt.Errorf("InsertOne: %v", err)
  817. }
  818. repo.IsMirror = true
  819. return repo, UpdateRepository(repo, false)
  820. }
  821. return CleanUpMigrateInfo(repo)
  822. }
  823. // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
  824. // This also removes possible user credentials.
  825. func cleanUpMigrateGitConfig(configPath string) error {
  826. cfg, err := ini.Load(configPath)
  827. if err != nil {
  828. return fmt.Errorf("open config file: %v", err)
  829. }
  830. cfg.DeleteSection("remote \"origin\"")
  831. if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
  832. return fmt.Errorf("save config file: %v", err)
  833. }
  834. return nil
  835. }
  836. // createDelegateHooks creates all the hooks scripts for the repo
  837. func createDelegateHooks(repoPath string) (err error) {
  838. var (
  839. hookNames = []string{"pre-receive", "update", "post-receive"}
  840. hookTpls = []string{
  841. fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
  842. fmt.Sprintf("#!/usr/bin/env %s\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\n\"${hook}\" $1 $2 $3\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
  843. fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
  844. }
  845. giteaHookTpls = []string{
  846. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  847. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  848. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' post-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  849. }
  850. )
  851. hookDir := filepath.Join(repoPath, "hooks")
  852. for i, hookName := range hookNames {
  853. oldHookPath := filepath.Join(hookDir, hookName)
  854. newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")
  855. if err := os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil {
  856. return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err)
  857. }
  858. // WARNING: This will override all old server-side hooks
  859. if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
  860. return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
  861. }
  862. if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
  863. return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
  864. }
  865. }
  866. return nil
  867. }
  868. // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
  869. func CleanUpMigrateInfo(repo *Repository) (*Repository, error) {
  870. repoPath := repo.RepoPath()
  871. if err := createDelegateHooks(repoPath); err != nil {
  872. return repo, fmt.Errorf("createDelegateHooks: %v", err)
  873. }
  874. if repo.HasWiki() {
  875. if err := createDelegateHooks(repo.WikiPath()); err != nil {
  876. return repo, fmt.Errorf("createDelegateHooks.(wiki): %v", err)
  877. }
  878. }
  879. if err := cleanUpMigrateGitConfig(repo.GitConfigPath()); err != nil {
  880. return repo, fmt.Errorf("cleanUpMigrateGitConfig: %v", err)
  881. }
  882. if repo.HasWiki() {
  883. if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
  884. return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
  885. }
  886. }
  887. return repo, UpdateRepository(repo, false)
  888. }
  889. // initRepoCommit temporarily changes with work directory.
  890. func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
  891. var stderr string
  892. if _, stderr, err = process.GetManager().ExecDir(-1,
  893. tmpPath, fmt.Sprintf("initRepoCommit (git add): %s", tmpPath),
  894. "git", "add", "--all"); err != nil {
  895. return fmt.Errorf("git add: %s", stderr)
  896. }
  897. if _, stderr, err = process.GetManager().ExecDir(-1,
  898. tmpPath, fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath),
  899. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  900. "-m", "Initial commit"); err != nil {
  901. return fmt.Errorf("git commit: %s", stderr)
  902. }
  903. if _, stderr, err = process.GetManager().ExecDir(-1,
  904. tmpPath, fmt.Sprintf("initRepoCommit (git push): %s", tmpPath),
  905. "git", "push", "origin", "master"); err != nil {
  906. return fmt.Errorf("git push: %s", stderr)
  907. }
  908. return nil
  909. }
  910. // CreateRepoOptions contains the create repository options
  911. type CreateRepoOptions struct {
  912. Name string
  913. Description string
  914. Gitignores string
  915. License string
  916. Readme string
  917. IsPrivate bool
  918. IsMirror bool
  919. AutoInit bool
  920. }
  921. func getRepoInitFile(tp, name string) ([]byte, error) {
  922. cleanedName := strings.TrimLeft(name, "./")
  923. relPath := path.Join("options", tp, cleanedName)
  924. // Use custom file when available.
  925. customPath := path.Join(setting.CustomPath, relPath)
  926. if com.IsFile(customPath) {
  927. return ioutil.ReadFile(customPath)
  928. }
  929. switch tp {
  930. case "readme":
  931. return options.Readme(cleanedName)
  932. case "gitignore":
  933. return options.Gitignore(cleanedName)
  934. case "license":
  935. return options.License(cleanedName)
  936. case "label":
  937. return options.Labels(cleanedName)
  938. default:
  939. return []byte{}, fmt.Errorf("Invalid init file type")
  940. }
  941. }
  942. func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
  943. // Clone to temporary path and do the init commit.
  944. _, stderr, err := process.GetManager().Exec(
  945. fmt.Sprintf("initRepository(git clone): %s", repoPath),
  946. "git", "clone", repoPath, tmpDir,
  947. )
  948. if err != nil {
  949. return fmt.Errorf("git clone: %v - %s", err, stderr)
  950. }
  951. // README
  952. data, err := getRepoInitFile("readme", opts.Readme)
  953. if err != nil {
  954. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
  955. }
  956. cloneLink := repo.CloneLink()
  957. match := map[string]string{
  958. "Name": repo.Name,
  959. "Description": repo.Description,
  960. "CloneURL.SSH": cloneLink.SSH,
  961. "CloneURL.HTTPS": cloneLink.HTTPS,
  962. }
  963. if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
  964. []byte(com.Expand(string(data), match)), 0644); err != nil {
  965. return fmt.Errorf("write README.md: %v", err)
  966. }
  967. // .gitignore
  968. if len(opts.Gitignores) > 0 {
  969. var buf bytes.Buffer
  970. names := strings.Split(opts.Gitignores, ",")
  971. for _, name := range names {
  972. data, err = getRepoInitFile("gitignore", name)
  973. if err != nil {
  974. return fmt.Errorf("getRepoInitFile[%s]: %v", name, err)
  975. }
  976. buf.WriteString("# ---> " + name + "\n")
  977. buf.Write(data)
  978. buf.WriteString("\n")
  979. }
  980. if buf.Len() > 0 {
  981. if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
  982. return fmt.Errorf("write .gitignore: %v", err)
  983. }
  984. }
  985. }
  986. // LICENSE
  987. if len(opts.License) > 0 {
  988. data, err = getRepoInitFile("license", opts.License)
  989. if err != nil {
  990. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
  991. }
  992. if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
  993. return fmt.Errorf("write LICENSE: %v", err)
  994. }
  995. }
  996. return nil
  997. }
  998. // InitRepository initializes README and .gitignore if needed.
  999. func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts CreateRepoOptions) (err error) {
  1000. // Somehow the directory could exist.
  1001. if com.IsExist(repoPath) {
  1002. return fmt.Errorf("initRepository: path already exists: %s", repoPath)
  1003. }
  1004. // Init bare new repository.
  1005. if err = git.InitRepository(repoPath, true); err != nil {
  1006. return fmt.Errorf("InitRepository: %v", err)
  1007. } else if err = createDelegateHooks(repoPath); err != nil {
  1008. return fmt.Errorf("createDelegateHooks: %v", err)
  1009. }
  1010. tmpDir := filepath.Join(os.TempDir(), "gitea-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  1011. // Initialize repository according to user's choice.
  1012. if opts.AutoInit {
  1013. if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
  1014. return fmt.Errorf("Failed to create dir %s: %v", tmpDir, err)
  1015. }
  1016. defer os.RemoveAll(tmpDir)
  1017. if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
  1018. return fmt.Errorf("prepareRepoCommit: %v", err)
  1019. }
  1020. // Apply changes and commit.
  1021. if err = initRepoCommit(tmpDir, u.NewGitSig()); err != nil {
  1022. return fmt.Errorf("initRepoCommit: %v", err)
  1023. }
  1024. }
  1025. // Re-fetch the repository from database before updating it (else it would
  1026. // override changes that were done earlier with sql)
  1027. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  1028. return fmt.Errorf("getRepositoryByID: %v", err)
  1029. }
  1030. if !opts.AutoInit {
  1031. repo.IsBare = true
  1032. }
  1033. repo.DefaultBranch = "master"
  1034. if err = updateRepository(e, repo, false); err != nil {
  1035. return fmt.Errorf("updateRepository: %v", err)
  1036. }
  1037. return nil
  1038. }
  1039. var (
  1040. reservedRepoNames = []string{".", ".."}
  1041. reservedRepoPatterns = []string{"*.git", "*.wiki"}
  1042. )
  1043. // IsUsableRepoName returns true when repository is usable
  1044. func IsUsableRepoName(name string) error {
  1045. return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
  1046. }
  1047. func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err error) {
  1048. if err = IsUsableRepoName(repo.Name); err != nil {
  1049. return err
  1050. }
  1051. has, err := isRepositoryExist(e, u, repo.Name)
  1052. if err != nil {
  1053. return fmt.Errorf("IsRepositoryExist: %v", err)
  1054. } else if has {
  1055. return ErrRepoAlreadyExist{u.Name, repo.Name}
  1056. }
  1057. if _, err = e.Insert(repo); err != nil {
  1058. return err
  1059. }
  1060. if err = deleteRepoRedirect(e, u.ID, repo.Name); err != nil {
  1061. return err
  1062. }
  1063. // insert units for repo
  1064. var units = make([]RepoUnit, 0, len(defaultRepoUnits))
  1065. for i, tp := range defaultRepoUnits {
  1066. if tp == UnitTypeIssues {
  1067. units = append(units, RepoUnit{
  1068. RepoID: repo.ID,
  1069. Type: tp,
  1070. Index: i,
  1071. Config: &IssuesConfig{EnableTimetracker: setting.Service.DefaultEnableTimetracking, AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime},
  1072. })
  1073. } else {
  1074. units = append(units, RepoUnit{
  1075. RepoID: repo.ID,
  1076. Type: tp,
  1077. Index: i,
  1078. })
  1079. }
  1080. }
  1081. if _, err = e.Insert(&units); err != nil {
  1082. return err
  1083. }
  1084. u.NumRepos++
  1085. // Remember visibility preference.
  1086. u.LastRepoVisibility = repo.IsPrivate
  1087. if err = updateUser(e, u); err != nil {
  1088. return fmt.Errorf("updateUser: %v", err)
  1089. }
  1090. // Give access to all members in owner team.
  1091. if u.IsOrganization() {
  1092. t, err := u.getOwnerTeam(e)
  1093. if err != nil {
  1094. return fmt.Errorf("getOwnerTeam: %v", err)
  1095. } else if err = t.addRepository(e, repo); err != nil {
  1096. return fmt.Errorf("addRepository: %v", err)
  1097. } else if err = prepareWebhooks(e, repo, HookEventRepository, &api.RepositoryPayload{
  1098. Action: api.HookRepoCreated,
  1099. Repository: repo.APIFormat(AccessModeOwner),
  1100. Organization: u.APIFormat(),
  1101. Sender: doer.APIFormat(),
  1102. }); err != nil {
  1103. return fmt.Errorf("prepareWebhooks: %v", err)
  1104. }
  1105. go HookQueue.Add(repo.ID)
  1106. } else {
  1107. // Organization automatically called this in addRepository method.
  1108. if err = repo.recalculateAccesses(e); err != nil {
  1109. return fmt.Errorf("recalculateAccesses: %v", err)
  1110. }
  1111. }
  1112. if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
  1113. return fmt.Errorf("watchRepo: %v", err)
  1114. } else if err = newRepoAction(e, u, repo); err != nil {
  1115. return fmt.Errorf("newRepoAction: %v", err)
  1116. }
  1117. return nil
  1118. }
  1119. // CreateRepository creates a repository for the user/organization u.
  1120. func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err error) {
  1121. if !u.CanCreateRepo() {
  1122. return nil, ErrReachLimitOfRepo{u.MaxRepoCreation}
  1123. }
  1124. repo := &Repository{
  1125. OwnerID: u.ID,
  1126. Owner: u,
  1127. Name: opts.Name,
  1128. LowerName: strings.ToLower(opts.Name),
  1129. Description: opts.Description,
  1130. IsPrivate: opts.IsPrivate,
  1131. }
  1132. sess := x.NewSession()
  1133. defer sess.Close()
  1134. if err = sess.Begin(); err != nil {
  1135. return nil, err
  1136. }
  1137. if err = createRepository(sess, doer, u, repo); err != nil {
  1138. return nil, err
  1139. }
  1140. // No need for init mirror.
  1141. if !opts.IsMirror {
  1142. repoPath := RepoPath(u.Name, repo.Name)
  1143. if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
  1144. if err2 := os.RemoveAll(repoPath); err2 != nil {
  1145. log.Error(4, "initRepository: %v", err)
  1146. return nil, fmt.Errorf(
  1147. "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
  1148. }
  1149. return nil, fmt.Errorf("initRepository: %v", err)
  1150. }
  1151. _, stderr, err := process.GetManager().ExecDir(-1,
  1152. repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath),
  1153. "git", "update-server-info")
  1154. if err != nil {
  1155. return nil, errors.New("CreateRepository(git update-server-info): " + stderr)
  1156. }
  1157. }
  1158. return repo, sess.Commit()
  1159. }
  1160. func countRepositories(userID int64, private bool) int64 {
  1161. sess := x.Where("id > 0")
  1162. if userID > 0 {
  1163. sess.And("owner_id = ?", userID)
  1164. }
  1165. if !private {
  1166. sess.And("is_private=?", false)
  1167. }
  1168. count, err := sess.Count(new(Repository))
  1169. if err != nil {
  1170. log.Error(4, "countRepositories: %v", err)
  1171. }
  1172. return count
  1173. }
  1174. // CountRepositories returns number of repositories.
  1175. // Argument private only takes effect when it is false,
  1176. // set it true to count all repositories.
  1177. func CountRepositories(private bool) int64 {
  1178. return countRepositories(-1, private)
  1179. }
  1180. // CountUserRepositories returns number of repositories user owns.
  1181. // Argument private only takes effect when it is false,
  1182. // set it true to count all repositories.
  1183. func CountUserRepositories(userID int64, private bool) int64 {
  1184. return countRepositories(userID, private)
  1185. }
  1186. // RepoPath returns repository path by given user and repository name.
  1187. func RepoPath(userName, repoName string) string {
  1188. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  1189. }
  1190. // TransferOwnership transfers all corresponding setting from old user to new one.
  1191. func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error {
  1192. newOwner, err := GetUserByName(newOwnerName)
  1193. if err != nil {
  1194. return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
  1195. }
  1196. // Check if new owner has repository with same name.
  1197. has, err := IsRepositoryExist(newOwner, repo.Name)
  1198. if err != nil {
  1199. return fmt.Errorf("IsRepositoryExist: %v", err)
  1200. } else if has {
  1201. return ErrRepoAlreadyExist{newOwnerName, repo.Name}
  1202. }
  1203. sess := x.NewSession()
  1204. defer sess.Close()
  1205. if err = sess.Begin(); err != nil {
  1206. return fmt.Errorf("sess.Begin: %v", err)
  1207. }
  1208. owner := repo.Owner
  1209. // Note: we have to set value here to make sure recalculate accesses is based on
  1210. // new owner.
  1211. repo.OwnerID = newOwner.ID
  1212. repo.Owner = newOwner
  1213. // Update repository.
  1214. if _, err := sess.Id(repo.ID).Update(repo); err != nil {
  1215. return fmt.Errorf("update owner: %v", err)
  1216. }
  1217. // Remove redundant collaborators.
  1218. collaborators, err := repo.getCollaborators(sess)
  1219. if err != nil {
  1220. return fmt.Errorf("getCollaborators: %v", err)
  1221. }
  1222. // Dummy object.
  1223. collaboration := &Collaboration{RepoID: repo.ID}
  1224. for _, c := range collaborators {
  1225. collaboration.UserID = c.ID
  1226. if c.ID == newOwner.ID || newOwner.IsOrgMember(c.ID) {
  1227. if _, err = sess.Delete(collaboration); err != nil {
  1228. return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
  1229. }
  1230. }
  1231. }
  1232. // Remove old team-repository relations.
  1233. if owner.IsOrganization() {
  1234. if err = owner.getTeams(sess); err != nil {
  1235. return fmt.Errorf("getTeams: %v", err)
  1236. }
  1237. for _, t := range owner.Teams {
  1238. if !t.hasRepository(sess, repo.ID) {
  1239. continue
  1240. }
  1241. t.NumRepos--
  1242. if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil {
  1243. return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
  1244. }
  1245. }
  1246. if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
  1247. return fmt.Errorf("removeOrgRepo: %v", err)
  1248. }
  1249. }
  1250. if newOwner.IsOrganization() {
  1251. t, err := newOwner.getOwnerTeam(sess)
  1252. if err != nil {
  1253. return fmt.Errorf("getOwnerTeam: %v", err)
  1254. } else if err = t.addRepository(sess, repo); err != nil {
  1255. return fmt.Errorf("add to owner team: %v", err)
  1256. }
  1257. } else {
  1258. // Organization called this in addRepository method.
  1259. if err = repo.recalculateAccesses(sess); err != nil {
  1260. return fmt.Errorf("recalculateAccesses: %v", err)
  1261. }
  1262. }
  1263. // Update repository count.
  1264. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
  1265. return fmt.Errorf("increase new owner repository count: %v", err)
  1266. } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
  1267. return fmt.Errorf("decrease old owner repository count: %v", err)
  1268. }
  1269. if err = watchRepo(sess, newOwner.ID, repo.ID, true); err != nil {
  1270. return fmt.Errorf("watchRepo: %v", err)
  1271. } else if err = transferRepoAction(sess, doer, owner, repo); err != nil {
  1272. return fmt.Errorf("transferRepoAction: %v", err)
  1273. }
  1274. // Rename remote repository to new path and delete local copy.
  1275. dir := UserPath(newOwner.Name)
  1276. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  1277. return fmt.Errorf("Failed to create dir %s: %v", dir, err)
  1278. }
  1279. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
  1280. return fmt.Errorf("rename repository directory: %v", err)
  1281. }
  1282. RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath())
  1283. // Rename remote wiki repository to new path and delete local copy.
  1284. wikiPath := WikiPath(owner.Name, repo.Name)
  1285. if com.IsExist(wikiPath) {
  1286. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1287. if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
  1288. return fmt.Errorf("rename repository wiki: %v", err)
  1289. }
  1290. }
  1291. return sess.Commit()
  1292. }
  1293. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  1294. func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) {
  1295. oldRepoName = strings.ToLower(oldRepoName)
  1296. newRepoName = strings.ToLower(newRepoName)
  1297. if err = IsUsableRepoName(newRepoName); err != nil {
  1298. return err
  1299. }
  1300. has, err := IsRepositoryExist(u, newRepoName)
  1301. if err != nil {
  1302. return fmt.Errorf("IsRepositoryExist: %v", err)
  1303. } else if has {
  1304. return ErrRepoAlreadyExist{u.Name, newRepoName}
  1305. }
  1306. repo, err := GetRepositoryByName(u.ID, oldRepoName)
  1307. if err != nil {
  1308. return fmt.Errorf("GetRepositoryByName: %v", err)
  1309. }
  1310. // Change repository directory name.
  1311. if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
  1312. return fmt.Errorf("rename repository directory: %v", err)
  1313. }
  1314. wikiPath := repo.WikiPath()
  1315. if com.IsExist(wikiPath) {
  1316. if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
  1317. return fmt.Errorf("rename repository wiki: %v", err)
  1318. }
  1319. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1320. }
  1321. return nil
  1322. }
  1323. func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {
  1324. repos := make([]*Repository, 0, 10)
  1325. return repos, e.
  1326. Where("fork_id=?", forkID).
  1327. Find(&repos)
  1328. }
  1329. // GetRepositoriesByForkID returns all repositories with given fork ID.
  1330. func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
  1331. return getRepositoriesByForkID(x, forkID)
  1332. }
  1333. func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
  1334. repo.LowerName = strings.ToLower(repo.Name)
  1335. if len(repo.Description) > 255 {
  1336. repo.Description = repo.Description[:255]
  1337. }
  1338. if len(repo.Website) > 255 {
  1339. repo.Website = repo.Website[:255]
  1340. }
  1341. if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
  1342. return fmt.Errorf("update: %v", err)
  1343. }
  1344. if visibilityChanged {
  1345. if err = repo.getOwner(e); err != nil {
  1346. return fmt.Errorf("getOwner: %v", err)
  1347. }
  1348. if repo.Owner.IsOrganization() {
  1349. // Organization repository need to recalculate access table when visibility is changed.
  1350. if err = repo.recalculateTeamAccesses(e, 0); err != nil {
  1351. return fmt.Errorf("recalculateTeamAccesses: %v", err)
  1352. }
  1353. }
  1354. // If repo has become private, we need to set its actions to private.
  1355. if repo.IsPrivate {
  1356. _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{
  1357. IsPrivate: true,
  1358. })
  1359. if err != nil {
  1360. return err
  1361. }
  1362. }
  1363. // Create/Remove git-daemon-export-ok for git-daemon...
  1364. daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
  1365. if repo.IsPrivate && com.IsExist(daemonExportFile) {
  1366. if err = os.Remove(daemonExportFile); err != nil {
  1367. log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
  1368. }
  1369. } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
  1370. if f, err := os.Create(daemonExportFile); err != nil {
  1371. log.Error(4, "Failed to create %s: %v", daemonExportFile, err)
  1372. } else {
  1373. f.Close()
  1374. }
  1375. }
  1376. forkRepos, err := getRepositoriesByForkID(e, repo.ID)
  1377. if err != nil {
  1378. return fmt.Errorf("getRepositoriesByForkID: %v", err)
  1379. }
  1380. for i := range forkRepos {
  1381. forkRepos[i].IsPrivate = repo.IsPrivate
  1382. if err = updateRepository(e, forkRepos[i], true); err != nil {
  1383. return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
  1384. }
  1385. }
  1386. if err = repo.updateSize(e); err != nil {
  1387. log.Error(4, "Failed to update size for repository: %v", err)
  1388. }
  1389. }
  1390. return nil
  1391. }
  1392. // UpdateRepository updates a repository
  1393. func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
  1394. sess := x.NewSession()
  1395. defer sess.Close()
  1396. if err = sess.Begin(); err != nil {
  1397. return err
  1398. }
  1399. if err = updateRepository(sess, repo, visibilityChanged); err != nil {
  1400. return fmt.Errorf("updateRepository: %v", err)
  1401. }
  1402. return sess.Commit()
  1403. }
  1404. // UpdateRepositoryUnits updates a repository's units
  1405. func UpdateRepositoryUnits(repo *Repository, units []RepoUnit) (err error) {
  1406. sess := x.NewSession()
  1407. defer sess.Close()
  1408. if err = sess.Begin(); err != nil {
  1409. return err
  1410. }
  1411. if _, err = sess.Where("repo_id = ?", repo.ID).Delete(new(RepoUnit)); err != nil {
  1412. return err
  1413. }
  1414. if _, err = sess.Insert(units); err != nil {
  1415. return err
  1416. }
  1417. return sess.Commit()
  1418. }
  1419. // DeleteRepository deletes a repository for a user or organization.
  1420. func DeleteRepository(doer *User, uid, repoID int64) error {
  1421. // In case is a organization.
  1422. org, err := GetUserByID(uid)
  1423. if err != nil {
  1424. return err
  1425. }
  1426. if org.IsOrganization() {
  1427. if err = org.GetTeams(); err != nil {
  1428. return err
  1429. }
  1430. }
  1431. sess := x.NewSession()
  1432. defer sess.Close()
  1433. if err = sess.Begin(); err != nil {
  1434. return err
  1435. }
  1436. repo := &Repository{ID: repoID, OwnerID: uid}
  1437. has, err := sess.Get(repo)
  1438. if err != nil {
  1439. return err
  1440. } else if !has {
  1441. return ErrRepoNotExist{repoID, uid, ""}
  1442. }
  1443. if cnt, err := sess.Id(repoID).Delete(&Repository{}); err != nil {
  1444. return err
  1445. } else if cnt != 1 {
  1446. return ErrRepoNotExist{repoID, uid, ""}
  1447. }
  1448. if org.IsOrganization() {
  1449. for _, t := range org.Teams {
  1450. if !t.hasRepository(sess, repoID) {
  1451. continue
  1452. } else if err = t.removeRepository(sess, repo, false); err != nil {
  1453. return err
  1454. }
  1455. }
  1456. }
  1457. if err = deleteBeans(sess,
  1458. &Access{RepoID: repo.ID},
  1459. &Action{RepoID: repo.ID},
  1460. &Watch{RepoID: repoID},
  1461. &Star{RepoID: repoID},
  1462. &Mirror{RepoID: repoID},
  1463. &Milestone{RepoID: repoID},
  1464. &Release{RepoID: repoID},
  1465. &Collaboration{RepoID: repoID},
  1466. &PullRequest{BaseRepoID: repoID},
  1467. &RepoUnit{RepoID: repoID},
  1468. &RepoRedirect{RedirectRepoID: repoID},
  1469. ); err != nil {
  1470. return fmt.Errorf("deleteBeans: %v", err)
  1471. }
  1472. // Delete comments and attachments.
  1473. issueIDs := make([]int64, 0, 25)
  1474. attachmentPaths := make([]string, 0, len(issueIDs))
  1475. if err = sess.
  1476. Table("issue").
  1477. Cols("id").
  1478. Where("repo_id=?", repoID).
  1479. Find(&issueIDs); err != nil {
  1480. return err
  1481. }
  1482. if len(issueIDs) > 0 {
  1483. if _, err = sess.In("issue_id", issueIDs).Delete(&Comment{}); err != nil {
  1484. return err
  1485. }
  1486. if _, err = sess.In("issue_id", issueIDs).Delete(&IssueUser{}); err != nil {
  1487. return err
  1488. }
  1489. attachments := make([]*Attachment, 0, 5)
  1490. if err = sess.
  1491. In("issue_id", issueIDs).
  1492. Find(&attachments); err != nil {
  1493. return err
  1494. }
  1495. for j := range attachments {
  1496. attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
  1497. }
  1498. if _, err = sess.In("issue_id", issueIDs).Delete(&Attachment{}); err != nil {
  1499. return err
  1500. }
  1501. if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
  1502. return err
  1503. }
  1504. }
  1505. if _, err = sess.Where("repo_id = ?", repoID).Delete(new(RepoUnit)); err != nil {
  1506. return err
  1507. }
  1508. if repo.IsFork {
  1509. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
  1510. return fmt.Errorf("decrease fork count: %v", err)
  1511. }
  1512. }
  1513. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
  1514. return err
  1515. }
  1516. // FIXME: Remove repository files should be executed after transaction succeed.
  1517. repoPath := repo.repoPath(sess)
  1518. removeAllWithNotice(sess, "Delete repository files", repoPath)
  1519. repo.deleteWiki(sess)
  1520. // Remove attachment files.
  1521. for i := range attachmentPaths {
  1522. removeAllWithNotice(sess, "Delete attachment", attachmentPaths[i])
  1523. }
  1524. // Remove LFS objects
  1525. var lfsObjects []*LFSMetaObject
  1526. if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
  1527. return err
  1528. }
  1529. for _, v := range lfsObjects {
  1530. count, err := sess.Count(&LFSMetaObject{Oid: v.Oid})
  1531. if err != nil {
  1532. return err
  1533. }
  1534. if count > 1 {
  1535. continue
  1536. }
  1537. oidPath := filepath.Join(v.Oid[0:2], v.Oid[2:4], v.Oid[4:len(v.Oid)])
  1538. err = os.Remove(filepath.Join(setting.LFS.ContentPath, oidPath))
  1539. if err != nil {
  1540. return err
  1541. }
  1542. }
  1543. if _, err := sess.Delete(&LFSMetaObject{RepositoryID: repoID}); err != nil {
  1544. return err
  1545. }
  1546. if repo.NumForks > 0 {
  1547. if _, err = sess.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
  1548. log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
  1549. }
  1550. }
  1551. if err = sess.Commit(); err != nil {
  1552. return fmt.Errorf("Commit: %v", err)
  1553. }
  1554. if org.IsOrganization() {
  1555. if err = PrepareWebhooks(repo, HookEventRepository, &api.RepositoryPayload{
  1556. Action: api.HookRepoDeleted,
  1557. Repository: repo.APIFormat(AccessModeOwner),
  1558. Organization: org.APIFormat(),
  1559. Sender: doer.APIFormat(),
  1560. }); err != nil {
  1561. return err
  1562. }
  1563. go HookQueue.Add(repo.ID)
  1564. }
  1565. return nil
  1566. }
  1567. // GetRepositoryByRef returns a Repository specified by a GFM reference.
  1568. // See https://help.github.com/articles/writing-on-github#references for more information on the syntax.
  1569. func GetRepositoryByRef(ref string) (*Repository, error) {
  1570. n := strings.IndexByte(ref, byte('/'))
  1571. if n < 2 {
  1572. return nil, ErrInvalidReference
  1573. }
  1574. userName, repoName := ref[:n], ref[n+1:]
  1575. user, err := GetUserByName(userName)
  1576. if err != nil {
  1577. return nil, err
  1578. }
  1579. return GetRepositoryByName(user.ID, repoName)
  1580. }
  1581. // GetRepositoryByName returns the repository by given name under user if exists.
  1582. func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
  1583. repo := &Repository{
  1584. OwnerID: ownerID,
  1585. LowerName: strings.ToLower(name),
  1586. }
  1587. has, err := x.Get(repo)
  1588. if err != nil {
  1589. return nil, err
  1590. } else if !has {
  1591. return nil, ErrRepoNotExist{0, ownerID, name}
  1592. }
  1593. return repo, err
  1594. }
  1595. func getRepositoryByID(e Engine, id int64) (*Repository, error) {
  1596. repo := new(Repository)
  1597. has, err := e.Id(id).Get(repo)
  1598. if err != nil {
  1599. return nil, err
  1600. } else if !has {
  1601. return nil, ErrRepoNotExist{id, 0, ""}
  1602. }
  1603. return repo, nil
  1604. }
  1605. // GetRepositoryByID returns the repository by given id if exists.
  1606. func GetRepositoryByID(id int64) (*Repository, error) {
  1607. return getRepositoryByID(x, id)
  1608. }
  1609. // GetUserRepositories returns a list of repositories of given user.
  1610. func GetUserRepositories(userID int64, private bool, page, pageSize int, orderBy string) ([]*Repository, error) {
  1611. if len(orderBy) == 0 {
  1612. orderBy = "updated_unix DESC"
  1613. }
  1614. sess := x.
  1615. Where("owner_id = ?", userID).
  1616. OrderBy(orderBy)
  1617. if !private {
  1618. sess.And("is_private=?", false)
  1619. }
  1620. if page <= 0 {
  1621. page = 1
  1622. }
  1623. sess.Limit(pageSize, (page-1)*pageSize)
  1624. repos := make([]*Repository, 0, pageSize)
  1625. return repos, sess.Find(&repos)
  1626. }
  1627. // GetUserMirrorRepositories returns a list of mirror repositories of given user.
  1628. func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
  1629. repos := make([]*Repository, 0, 10)
  1630. return repos, x.
  1631. Where("owner_id = ?", userID).
  1632. And("is_mirror = ?", true).
  1633. Find(&repos)
  1634. }
  1635. func getRepositoryCount(e Engine, u *User) (int64, error) {
  1636. return e.Count(&Repository{OwnerID: u.ID})
  1637. }
  1638. func getPublicRepositoryCount(e Engine, u *User) (int64, error) {
  1639. return e.Where("is_private = ?", false).Count(&Repository{OwnerID: u.ID})
  1640. }
  1641. func getPrivateRepositoryCount(e Engine, u *User) (int64, error) {
  1642. return e.Where("is_private = ?", true).Count(&Repository{OwnerID: u.ID})
  1643. }
  1644. // GetRepositoryCount returns the total number of repositories of user.
  1645. func GetRepositoryCount(u *User) (int64, error) {
  1646. return getRepositoryCount(x, u)
  1647. }
  1648. // GetPublicRepositoryCount returns the total number of public repositories of user.
  1649. func GetPublicRepositoryCount(u *User) (int64, error) {
  1650. return getPublicRepositoryCount(x, u)
  1651. }
  1652. // GetPrivateRepositoryCount returns the total number of private repositories of user.
  1653. func GetPrivateRepositoryCount(u *User) (int64, error) {
  1654. return getPrivateRepositoryCount(x, u)
  1655. }
  1656. // DeleteRepositoryArchives deletes all repositories' archives.
  1657. func DeleteRepositoryArchives() error {
  1658. return x.
  1659. Where("id > 0").
  1660. Iterate(new(Repository),
  1661. func(idx int, bean interface{}) error {
  1662. repo := bean.(*Repository)
  1663. return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
  1664. })
  1665. }
  1666. // DeleteOldRepositoryArchives deletes old repository archives.
  1667. func DeleteOldRepositoryArchives() {
  1668. if !taskStatusTable.StartIfNotRunning(archiveCleanup) {
  1669. return
  1670. }
  1671. defer taskStatusTable.Stop(archiveCleanup)
  1672. log.Trace("Doing: ArchiveCleanup")
  1673. if err := x.Where("id > 0").Iterate(new(Repository), deleteOldRepositoryArchives); err != nil {
  1674. log.Error(4, "ArchiveClean: %v", err)
  1675. }
  1676. }
  1677. func deleteOldRepositoryArchives(idx int, bean interface{}) error {
  1678. repo := bean.(*Repository)
  1679. basePath := filepath.Join(repo.RepoPath(), "archives")
  1680. for _, ty := range []string{"zip", "targz"} {
  1681. path := filepath.Join(basePath, ty)
  1682. file, err := os.Open(path)
  1683. if err != nil {
  1684. if !os.IsNotExist(err) {
  1685. log.Warn("Unable to open directory %s: %v", path, err)
  1686. return err
  1687. }
  1688. // If the directory doesn't exist, that's okay.
  1689. continue
  1690. }
  1691. files, err := file.Readdir(0)
  1692. file.Close()
  1693. if err != nil {
  1694. log.Warn("Unable to read directory %s: %v", path, err)
  1695. return err
  1696. }
  1697. minimumOldestTime := time.Now().Add(-setting.Cron.ArchiveCleanup.OlderThan)
  1698. for _, info := range files {
  1699. if info.ModTime().Before(minimumOldestTime) && !info.IsDir() {
  1700. toDelete := filepath.Join(path, info.Name())
  1701. // This is a best-effort purge, so we do not check error codes to confirm removal.
  1702. if err = os.Remove(toDelete); err != nil {
  1703. log.Trace("Unable to delete %s, but proceeding: %v", toDelete, err)
  1704. }
  1705. }
  1706. }
  1707. }
  1708. return nil
  1709. }
  1710. func gatherMissingRepoRecords() ([]*Repository, error) {
  1711. repos := make([]*Repository, 0, 10)
  1712. if err := x.
  1713. Where("id > 0").
  1714. Iterate(new(Repository),
  1715. func(idx int, bean interface{}) error {
  1716. repo := bean.(*Repository)
  1717. if !com.IsDir(repo.RepoPath()) {
  1718. repos = append(repos, repo)
  1719. }
  1720. return nil
  1721. }); err != nil {
  1722. if err2 := CreateRepositoryNotice(fmt.Sprintf("gatherMissingRepoRecords: %v", err)); err2 != nil {
  1723. return nil, fmt.Errorf("CreateRepositoryNotice: %v", err)
  1724. }
  1725. }
  1726. return repos, nil
  1727. }
  1728. // DeleteMissingRepositories deletes all repository records that lost Git files.
  1729. func DeleteMissingRepositories(doer *User) error {
  1730. repos, err := gatherMissingRepoRecords()
  1731. if err != nil {
  1732. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1733. }
  1734. if len(repos) == 0 {
  1735. return nil
  1736. }
  1737. for _, repo := range repos {
  1738. log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
  1739. if err := DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {
  1740. if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1741. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1742. }
  1743. }
  1744. }
  1745. return nil
  1746. }
  1747. // ReinitMissingRepositories reinitializes all repository records that lost Git files.
  1748. func ReinitMissingRepositories() error {
  1749. repos, err := gatherMissingRepoRecords()
  1750. if err != nil {
  1751. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1752. }
  1753. if len(repos) == 0 {
  1754. return nil
  1755. }
  1756. for _, repo := range repos {
  1757. log.Trace("Initializing %d/%d...", repo.OwnerID, repo.ID)
  1758. if err := git.InitRepository(repo.RepoPath(), true); err != nil {
  1759. if err2 := CreateRepositoryNotice(fmt.Sprintf("InitRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1760. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1761. }
  1762. }
  1763. }
  1764. return nil
  1765. }
  1766. // SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks
  1767. // to make sure the binary and custom conf path are up-to-date.
  1768. func SyncRepositoryHooks() error {
  1769. return x.Where("id > 0").Iterate(new(Repository),
  1770. func(idx int, bean interface{}) error {
  1771. if err := createDelegateHooks(bean.(*Repository).RepoPath()); err != nil {
  1772. return fmt.Errorf("SyncRepositoryHook: %v", err)
  1773. }
  1774. if bean.(*Repository).HasWiki() {
  1775. if err := createDelegateHooks(bean.(*Repository).WikiPath()); err != nil {
  1776. return fmt.Errorf("SyncRepositoryHook: %v", err)
  1777. }
  1778. }
  1779. return nil
  1780. })
  1781. }
  1782. // Prevent duplicate running tasks.
  1783. var taskStatusTable = sync.NewStatusTable()
  1784. const (
  1785. mirrorUpdate = "mirror_update"
  1786. gitFsck = "git_fsck"
  1787. checkRepos = "check_repos"
  1788. archiveCleanup = "archive_cleanup"
  1789. )
  1790. // GitFsck calls 'git fsck' to check repository health.
  1791. func GitFsck() {
  1792. if !taskStatusTable.StartIfNotRunning(gitFsck) {
  1793. return
  1794. }
  1795. defer taskStatusTable.Stop(gitFsck)
  1796. log.Trace("Doing: GitFsck")
  1797. if err := x.
  1798. Where("id>0").
  1799. Iterate(new(Repository),
  1800. func(idx int, bean interface{}) error {
  1801. repo := bean.(*Repository)
  1802. repoPath := repo.RepoPath()
  1803. if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
  1804. desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
  1805. log.Warn(desc)
  1806. if err = CreateRepositoryNotice(desc); err != nil {
  1807. log.Error(4, "CreateRepositoryNotice: %v", err)
  1808. }
  1809. }
  1810. return nil
  1811. }); err != nil {
  1812. log.Error(4, "GitFsck: %v", err)
  1813. }
  1814. }
  1815. // GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository
  1816. func GitGcRepos() error {
  1817. args := append([]string{"gc"}, setting.Git.GCArgs...)
  1818. return x.
  1819. Where("id > 0").
  1820. Iterate(new(Repository),
  1821. func(idx int, bean interface{}) error {
  1822. repo := bean.(*Repository)
  1823. if err := repo.GetOwner(); err != nil {
  1824. return err
  1825. }
  1826. _, stderr, err := process.GetManager().ExecDir(
  1827. time.Duration(setting.Git.Timeout.GC)*time.Second,
  1828. RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection",
  1829. "git", args...)
  1830. if err != nil {
  1831. return fmt.Errorf("%v: %v", err, stderr)
  1832. }
  1833. return nil
  1834. })
  1835. }
  1836. type repoChecker struct {
  1837. querySQL, correctSQL string
  1838. desc string
  1839. }
  1840. func repoStatsCheck(checker *repoChecker) {
  1841. results, err := x.Query(checker.querySQL)
  1842. if err != nil {
  1843. log.Error(4, "Select %s: %v", checker.desc, err)
  1844. return
  1845. }
  1846. for _, result := range results {
  1847. id := com.StrTo(result["id"]).MustInt64()
  1848. log.Trace("Updating %s: %d", checker.desc, id)
  1849. _, err = x.Exec(checker.correctSQL, id, id)
  1850. if err != nil {
  1851. log.Error(4, "Update %s[%d]: %v", checker.desc, id, err)
  1852. }
  1853. }
  1854. }
  1855. // CheckRepoStats checks the repository stats
  1856. func CheckRepoStats() {
  1857. if !taskStatusTable.StartIfNotRunning(checkRepos) {
  1858. return
  1859. }
  1860. defer taskStatusTable.Stop(checkRepos)
  1861. log.Trace("Doing: CheckRepoStats")
  1862. checkers := []*repoChecker{
  1863. // Repository.NumWatches
  1864. {
  1865. "SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id)",
  1866. "UPDATE `repository` SET num_watches=(SELECT COUNT(*) FROM `watch` WHERE repo_id=?) WHERE id=?",
  1867. "repository count 'num_watches'",
  1868. },
  1869. // Repository.NumStars
  1870. {
  1871. "SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)",
  1872. "UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?",
  1873. "repository count 'num_stars'",
  1874. },
  1875. // Label.NumIssues
  1876. {
  1877. "SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)",
  1878. "UPDATE `label` SET num_issues=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=?) WHERE id=?",
  1879. "label count 'num_issues'",
  1880. },
  1881. // User.NumRepos
  1882. {
  1883. "SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)",
  1884. "UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?",
  1885. "user count 'num_repos'",
  1886. },
  1887. // Issue.NumComments
  1888. {
  1889. "SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND type=0)",
  1890. "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND type=0) WHERE id=?",
  1891. "issue count 'num_comments'",
  1892. },
  1893. }
  1894. for i := range checkers {
  1895. repoStatsCheck(checkers[i])
  1896. }
  1897. // ***** START: Repository.NumClosedIssues *****
  1898. desc := "repository count 'num_closed_issues'"
  1899. 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)
  1900. if err != nil {
  1901. log.Error(4, "Select %s: %v", desc, err)
  1902. } else {
  1903. for _, result := range results {
  1904. id := com.StrTo(result["id"]).MustInt64()
  1905. log.Trace("Updating %s: %d", desc, id)
  1906. _, 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)
  1907. if err != nil {
  1908. log.Error(4, "Update %s[%d]: %v", desc, id, err)
  1909. }
  1910. }
  1911. }
  1912. // ***** END: Repository.NumClosedIssues *****
  1913. // FIXME: use checker when stop supporting old fork repo format.
  1914. // ***** START: Repository.NumForks *****
  1915. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
  1916. if err != nil {
  1917. log.Error(4, "Select repository count 'num_forks': %v", err)
  1918. } else {
  1919. for _, result := range results {
  1920. id := com.StrTo(result["id"]).MustInt64()
  1921. log.Trace("Updating repository count 'num_forks': %d", id)
  1922. repo, err := GetRepositoryByID(id)
  1923. if err != nil {
  1924. log.Error(4, "GetRepositoryByID[%d]: %v", id, err)
  1925. continue
  1926. }
  1927. rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
  1928. if err != nil {
  1929. log.Error(4, "Select count of forks[%d]: %v", repo.ID, err)
  1930. continue
  1931. }
  1932. repo.NumForks = int(parseCountResult(rawResult))
  1933. if err = UpdateRepository(repo, false); err != nil {
  1934. log.Error(4, "UpdateRepository[%d]: %v", id, err)
  1935. continue
  1936. }
  1937. }
  1938. }
  1939. // ***** END: Repository.NumForks *****
  1940. }
  1941. // ___________ __
  1942. // \_ _____/__________| | __
  1943. // | __)/ _ \_ __ \ |/ /
  1944. // | \( <_> ) | \/ <
  1945. // \___ / \____/|__| |__|_ \
  1946. // \/ \/
  1947. // HasForkedRepo checks if given user has already forked a repository with given ID.
  1948. func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
  1949. repo := new(Repository)
  1950. has, _ := x.
  1951. Where("owner_id=? AND fork_id=?", ownerID, repoID).
  1952. Get(repo)
  1953. return repo, has
  1954. }
  1955. // ForkRepository forks a repository
  1956. func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
  1957. forkedRepo, err := oldRepo.GetUserFork(u.ID)
  1958. if err != nil {
  1959. return nil, err
  1960. }
  1961. if forkedRepo != nil {
  1962. return nil, ErrRepoAlreadyExist{
  1963. Uname: u.Name,
  1964. Name: forkedRepo.Name,
  1965. }
  1966. }
  1967. repo := &Repository{
  1968. OwnerID: u.ID,
  1969. Owner: u,
  1970. Name: name,
  1971. LowerName: strings.ToLower(name),
  1972. Description: desc,
  1973. DefaultBranch: oldRepo.DefaultBranch,
  1974. IsPrivate: oldRepo.IsPrivate,
  1975. IsFork: true,
  1976. ForkID: oldRepo.ID,
  1977. }
  1978. sess := x.NewSession()
  1979. defer sess.Close()
  1980. if err = sess.Begin(); err != nil {
  1981. return nil, err
  1982. }
  1983. if err = createRepository(sess, doer, u, repo); err != nil {
  1984. return nil, err
  1985. }
  1986. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
  1987. return nil, err
  1988. }
  1989. repoPath := RepoPath(u.Name, repo.Name)
  1990. _, stderr, err := process.GetManager().ExecTimeout(10*time.Minute,
  1991. fmt.Sprintf("ForkRepository(git clone): %s/%s", u.Name, repo.Name),
  1992. "git", "clone", "--bare", oldRepo.RepoPath(), repoPath)
  1993. if err != nil {
  1994. return nil, fmt.Errorf("git clone: %v", stderr)
  1995. }
  1996. _, stderr, err = process.GetManager().ExecDir(-1,
  1997. repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath),
  1998. "git", "update-server-info")
  1999. if err != nil {
  2000. return nil, fmt.Errorf("git update-server-info: %v", stderr)
  2001. }
  2002. if err = createDelegateHooks(repoPath); err != nil {
  2003. return nil, fmt.Errorf("createDelegateHooks: %v", err)
  2004. }
  2005. //Commit repo to get Fork ID
  2006. err = sess.Commit()
  2007. if err != nil {
  2008. return nil, err
  2009. }
  2010. if err = repo.UpdateSize(); err != nil {
  2011. log.Error(4, "Failed to update size for repository: %v", err)
  2012. }
  2013. // Copy LFS meta objects in new session
  2014. sess2 := x.NewSession()
  2015. defer sess2.Close()
  2016. if err = sess2.Begin(); err != nil {
  2017. return nil, err
  2018. }
  2019. var lfsObjects []*LFSMetaObject
  2020. if err = sess2.Where("repository_id=?", oldRepo.ID).Find(&lfsObjects); err != nil {
  2021. return nil, err
  2022. }
  2023. for _, v := range lfsObjects {
  2024. v.ID = 0
  2025. v.RepositoryID = repo.ID
  2026. if _, err = sess2.Insert(v); err != nil {
  2027. return nil, err
  2028. }
  2029. }
  2030. return repo, sess2.Commit()
  2031. }
  2032. // GetForks returns all the forks of the repository
  2033. func (repo *Repository) GetForks() ([]*Repository, error) {
  2034. forks := make([]*Repository, 0, repo.NumForks)
  2035. return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
  2036. }
  2037. // GetUserFork return user forked repository from this repository, if not forked return nil
  2038. func (repo *Repository) GetUserFork(userID int64) (*Repository, error) {
  2039. var forkedRepo Repository
  2040. has, err := x.Where("fork_id = ?", repo.ID).And("owner_id = ?", userID).Get(&forkedRepo)
  2041. if err != nil {
  2042. return nil, err
  2043. }
  2044. if !has {
  2045. return nil, nil
  2046. }
  2047. return &forkedRepo, nil
  2048. }
  2049. // __________ .__
  2050. // \______ \____________ ____ ____ | |__
  2051. // | | _/\_ __ \__ \ / \_/ ___\| | \
  2052. // | | \ | | \// __ \| | \ \___| Y \
  2053. // |______ / |__| (____ /___| /\___ >___| /
  2054. // \/ \/ \/ \/ \/
  2055. //
  2056. // CreateNewBranch creates a new repository branch
  2057. func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
  2058. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  2059. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  2060. localPath := repo.LocalCopyPath()
  2061. if err = discardLocalRepoBranchChanges(localPath, oldBranchName); err != nil {
  2062. return fmt.Errorf("discardLocalRepoChanges: %v", err)
  2063. } else if err = repo.UpdateLocalCopyBranch(oldBranchName); err != nil {
  2064. return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
  2065. }
  2066. if err = repo.CheckoutNewBranch(oldBranchName, branchName); err != nil {
  2067. return fmt.Errorf("CreateNewBranch: %v", err)
  2068. }
  2069. if err = git.Push(localPath, git.PushOptions{
  2070. Remote: "origin",
  2071. Branch: branchName,
  2072. }); err != nil {
  2073. return fmt.Errorf("Push: %v", err)
  2074. }
  2075. return nil
  2076. }