-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix maintenance problem when changes are only on remote #201
Open
DenisFlorin
wants to merge
1
commit into
master
Choose a base branch
from
fix-error-when-saving-remote
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -94,29 +94,59 @@ public function save_ignorelist() { | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
public function save_changes() { | ||||||||||||||
$gitium_save_changes = filter_input(INPUT_POST, 'GitiumSubmitSaveChanges', FILTER_SANITIZE_FULL_SPECIAL_CHARS); | ||||||||||||||
$gitium_save_changes = filter_input(INPUT_POST, 'GitiumSubmitSaveChanges', FILTER_SANITIZE_FULL_SPECIAL_CHARS); | ||||||||||||||
$gitium_commit_msg = filter_input(INPUT_POST, 'commitmsg', FILTER_SANITIZE_FULL_SPECIAL_CHARS); | ||||||||||||||
if ( ! isset( $gitium_save_changes ) ) { | ||||||||||||||
if ( ! isset( $gitium_save_changes ) ) { | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
check_admin_referer( 'gitium-admin' ); | ||||||||||||||
|
||||||||||||||
gitium_enable_maintenance_mode() or wp_die( __( 'Could not enable the maintenance mode!', 'gitium' ) ); | ||||||||||||||
|
||||||||||||||
// Check if the local repository is behind the remote | ||||||||||||||
$behind_commits = $this->git->get_behind_commits(); | ||||||||||||||
if ( $behind_commits !== false && count($behind_commits) > 0 ) { | ||||||||||||||
// Perform a git pull if the local branch is behind | ||||||||||||||
if ( ! $this->git->pull() ) { | ||||||||||||||
gitium_disable_maintenance_mode(); | ||||||||||||||
$this->redirect( __( 'Could not pull the latest changes from the repository!', 'gitium' ) ); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Check if there are any changes in the working directory after pulling | ||||||||||||||
list( $branch_status, $new_response ) = $this->git->status(true); | ||||||||||||||
if (empty($new_response)) { | ||||||||||||||
// No changes to commit, exit maintenance mode and redirect with success | ||||||||||||||
gitium_disable_maintenance_mode(); | ||||||||||||||
$this->success_redirect( __( 'No changes to commit, repository is up-to-date.', 'gitium' ) ); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Add all changes in the working directory | ||||||||||||||
$this->git->add(); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
// Prepare the commit message | ||||||||||||||
$commitmsg = sprintf( __( 'Merged changes from %s on %s', 'gitium' ), get_site_url(), date( 'm.d.Y' ) ); | ||||||||||||||
if ( isset( $gitium_commit_msg ) && ! empty( $gitium_commit_msg ) ) { | ||||||||||||||
$commitmsg = $gitium_commit_msg; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$current_user = wp_get_current_user(); | ||||||||||||||
$commit = $this->git->commit( $commitmsg, $current_user->display_name, $current_user->user_email ); | ||||||||||||||
if ( ! $commit ) { | ||||||||||||||
gitium_disable_maintenance_mode(); | ||||||||||||||
$this->redirect( __( 'Could not commit!', 'gitium' ) ); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$merge_success = gitium_merge_and_push( $commit ); | ||||||||||||||
gitium_disable_maintenance_mode(); | ||||||||||||||
if ( ! $merge_success ) { | ||||||||||||||
$this->redirect( __( 'Merge failed: ', 'gitium' ) . $this->git->get_last_error() ); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$this->success_redirect( sprintf( __( 'Pushed commit: `%s`', 'gitium' ), $commitmsg ) ); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_behind_commits
runsgit rev-list
which comparse only commits that exists localy. In order to check comits on remote you have to run agit fetch
first, there is a function that I think does thatfetch_ref()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can inspire from
gitium_merge_and_push
function and callmerge_with_accept_mine
but there is a lock that it should be aquired. You can try calinggitium_merge_and_push
directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see that
gitium_merge_and_push
is called below at line 143.What is then issue that you try to fix? Do you have some STR, or maybe some errors messages ?
Maybe only calling gitium_disable_maintenace_mode is enough?
I see that this function
save_changes
only whenSave changes
button is pressed? Where problems with this?