diff options
author | zeapo <mohamed@zenadi.com> | 2017-08-10 22:46:05 +0200 |
---|---|---|
committer | zeapo <mohamed@zenadi.com> | 2017-08-10 22:46:05 +0200 |
commit | 8ae59a4922a61ce3f57e8bce8fbacbc43c873e08 (patch) | |
tree | b346cd3f9ebd2ac43d4c38da7892629d62101a57 | |
parent | 2ca8f94cb7ed4617cf309b26e1defb2f99e197f4 (diff) |
add a way to see the git status and abort a rebase
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java | 60 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java | 1 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_git_config.xml | 231 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 |
4 files changed, 192 insertions, 102 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java index 51ab863d..1a43fec4 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java @@ -26,6 +26,12 @@ import com.zeapo.pwdstore.UserPreference; import com.zeapo.pwdstore.utils.PasswordRepository; import org.apache.commons.io.FileUtils; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.RebaseCommand; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; import java.io.File; import java.io.IOException; @@ -252,13 +258,7 @@ public class GitActivity extends AppCompatActivity { setContentView(R.layout.activity_git_config); setTitle(R.string.title_activity_git_config); - // init the server information - final EditText git_user_name = ((EditText) findViewById(R.id.git_user_name)); - final EditText git_user_email = ((EditText) findViewById(R.id.git_user_email)); - - git_user_name.setText(settings.getString("git_config_user_name", "")); - git_user_email.setText(settings.getString("git_config_user_email", "")); - + showGitConfig(); break; case REQUEST_PULL: syncRepository(REQUEST_PULL); @@ -463,6 +463,29 @@ public class GitActivity extends AppCompatActivity { finish(); } + private void showGitConfig() { + // init the server information + final EditText git_user_name = ((EditText) findViewById(R.id.git_user_name)); + final EditText git_user_email = ((EditText) findViewById(R.id.git_user_email)); + + git_user_name.setText(settings.getString("git_config_user_name", "")); + git_user_email.setText(settings.getString("git_config_user_email", "")); + + // git status + Repository repo = PasswordRepository.getRepository(PasswordRepository.getRepositoryDirectory(activity.getApplicationContext())); + if (repo != null) { + final TextView git_commit_hash = (TextView) findViewById(R.id.git_commit_hash); + try { + ObjectId objectId = repo.resolve(Constants.HEAD); + Ref ref = repo.getRef("refs/heads/master"); + String head = ref.getObjectId().equals(objectId) ? ref.getName() : "DETACHED"; + git_commit_hash.setText(String.format("%s (%s)", objectId.abbreviate(8).name(), head)); + } catch (Exception e) { + // ignore + } + } + } + private boolean saveGitConfigs() { // remember the settings SharedPreferences.Editor editor = settings.edit(); @@ -473,9 +496,9 @@ public class GitActivity extends AppCompatActivity { if (!email.matches(emailPattern)) { new AlertDialog.Builder(this). - setMessage(activity.getResources().getString(R.string.invalid_email_dialog_text)). - setPositiveButton(activity.getResources().getString(R.string.dialog_oops), null). - show(); + setMessage(activity.getResources().getString(R.string.invalid_email_dialog_text)). + setPositiveButton(activity.getResources().getString(R.string.dialog_oops), null). + show(); return false; } @@ -484,7 +507,7 @@ public class GitActivity extends AppCompatActivity { } public void applyGitConfigs(View view) { - if(!saveGitConfigs()) + if (!saveGitConfigs()) return; String git_user_name = settings.getString("git_config_user_name", ""); @@ -496,6 +519,20 @@ public class GitActivity extends AppCompatActivity { finish(); } + public void abortRebase(View view) { + Repository repo = PasswordRepository.getRepository(PasswordRepository.getRepositoryDirectory(getApplicationContext())); + if (repo != null) { + try { + // no network or heavy computation done, it's ok to do it on the ui-thread + new Git(repo).rebase().setOperation(RebaseCommand.Operation.ABORT).call(); + } catch (Exception e) { + //ignore + } finally { + showGitConfig(); + } + } + } + /** * Clones the repository, the directory exists, deletes it */ @@ -573,6 +610,7 @@ public class GitActivity extends AppCompatActivity { /** * Syncs the local repository with the remote one (either pull or push) + * * @param operation the operation to execute can be REQUEST_PULL or REQUEST_PUSH */ private void syncRepository(int operation) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java index 6ca8bf49..9ab142c8 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java @@ -8,6 +8,7 @@ import com.zeapo.pwdstore.R; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.PullCommand; +import org.eclipse.jgit.merge.MergeStrategy; import java.io.File; diff --git a/app/src/main/res/layout/activity_git_config.xml b/app/src/main/res/layout/activity_git_config.xml index 87db8c9c..17deb499 100644 --- a/app/src/main/res/layout/activity_git_config.xml +++ b/app/src/main/res/layout/activity_git_config.xml @@ -1,96 +1,147 @@ -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/scrollView2" android:layout_width="match_parent" android:layout_height="match_parent" - android:paddingLeft="@dimen/activity_horizontal_margin" - android:paddingRight="@dimen/activity_horizontal_margin" - android:paddingTop="@dimen/activity_vertical_margin" - android:paddingBottom="@dimen/activity_vertical_margin" + android:background="@android:color/white" tools:context="com.zeapo.pwdstore.git.GitActivity" - android:background="@android:color/white"> + tools:layout_editor_absoluteX="0dp" + tools:layout_editor_absoluteY="81dp"> - <LinearLayout - android:layout_width="match_parent" + + <TextView + android:id="@+id/textView5" + style="@android:style/TextAppearance.Large" + android:layout_width="344dp" + android:layout_height="wrap_content" + android:layout_marginLeft="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:background="@drawable/bottom_line" + android:gravity="start" + android:paddingBottom="6dp" + android:text="@string/git_config" + android:textColor="@color/blue_grey_500" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + <TextView + android:id="@+id/label_git_user_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="8dp" + android:layout_marginStart="8dp" + android:paddingBottom="8dp" + android:text="@string/git_user_name" + app:layout_constraintBaseline_toBaselineOf="@+id/git_user_name" + app:layout_constraintStart_toStartOf="parent" /> + + <EditText + android:id="@+id/git_user_name" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:hint="@string/git_user_name_hint" + android:inputType="textWebEmailAddress" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@+id/label_git_user_name" + app:layout_constraintTop_toBottomOf="@+id/textView5" /> + + + <TextView + android:id="@+id/label_git_user_email" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:paddingBottom="8dp" + android:text="@string/git_user_email" + app:layout_constraintBaseline_toBaselineOf="@+id/git_user_email" + app:layout_constraintEnd_toEndOf="@+id/label_git_user_name" + app:layout_constraintStart_toStartOf="@+id/label_git_user_name" /> + + <EditText + android:id="@+id/git_user_email" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="8dp" + android:hint="@string/git_user_email_hint" + android:inputType="textWebEmailAddress" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="@+id/git_user_name" + app:layout_constraintTop_toBottomOf="@+id/git_user_name" /> + + + <Button + android:id="@+id/save_button" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="8dp" + android:onClick="applyGitConfigs" + android:text="@string/crypto_save" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/git_user_email" /> + + <TextView + android:id="@+id/textView6" + style="@android:style/TextAppearance.Large" + android:layout_width="344dp" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:background="@drawable/bottom_line" + android:gravity="start" + android:paddingBottom="6dp" + android:text="Hackish tools" + android:textColor="@color/blue_grey_500" + android:textStyle="bold" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/save_button" /> + + <Button + android:id="@+id/git_abort_rebase" + android:layout_width="0dp" android:layout_height="wrap_content" - android:orientation="vertical"> - - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/git_config" - android:textStyle="bold" - style="@android:style/TextAppearance.Large" - android:gravity="start" - android:paddingBottom="6dp" - android:textColor="@color/blue_grey_500" - android:background="@drawable/bottom_line"/> - - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:layout_gravity="center_vertical"> - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/git_user_name" - android:id="@+id/label_git_user_name" - android:layout_centerVertical="true" - android:layout_alignParentLeft="true" - android:paddingBottom="8dp" - android:layout_alignParentStart="true" /> - - <EditText - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:hint="@string/git_user_name_hint" - android:id="@+id/git_user_name" - android:layout_marginLeft="8dp" - android:layout_marginStart="8dp" - android:layout_toEndOf="@+id/label_git_user_name" - android:layout_toRightOf="@+id/label_git_user_name" - android:layout_alignParentRight="true" - android:layout_alignParentEnd="true" - android:inputType="textWebEmailAddress"/> - </RelativeLayout> - - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:layout_gravity="center_vertical"> - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/git_user_email" - android:id="@+id/label_git_user_email" - android:layout_centerVertical="true" - android:layout_alignParentLeft="true" - android:paddingBottom="8dp" - android:layout_alignParentStart="true" /> - - <EditText - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:hint="@string/git_user_email_hint" - android:id="@+id/git_user_email" - android:layout_marginLeft="35dp" - android:layout_marginStart="35dp" - android:layout_toEndOf="@+id/label_git_user_email" - android:layout_toRightOf="@+id/label_git_user_email" - android:layout_alignParentRight="true" - android:layout_alignParentEnd="true" - android:inputType="textWebEmailAddress"/> - </RelativeLayout> - - <Button - android:id="@+id/save_button" - android:text="@string/crypto_save" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:onClick="applyGitConfigs"/> - </LinearLayout> - -</ScrollView> + android:layout_marginEnd="8dp" + android:layout_marginLeft="16dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:onClick="abortRebase" + android:text="Abort rebase" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView7" /> + + <TextView + android:id="@+id/textView7" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:text="Commit hash" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView6" /> + + <TextView + android:id="@+id/git_commit_hash" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:text="HASH" + android:textStyle="bold" + app:layout_constraintBaseline_toBaselineOf="@+id/textView7" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintStart_toEndOf="@+id/textView7" /> + + +</android.support.constraint.ConstraintLayout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a73b5ef5..e9ad089b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -100,7 +100,7 @@ <!-- Preferences --> <string name="pref_git_title">Git</string> <string name="pref_edit_server_info">Edit git server settings</string> - <string name="pref_edit_git_config">Edit git config</string> + <string name="pref_edit_git_config">Git utils</string> <string name="pref_ssh_title">Import SSH key</string> <string name="pref_ssh_keygen_title">Generate SSH key pair</string> <string name="pref_ssh_see_key_title">View generated public SSH key</string> |