diff --git a/app/src/main/java/com/orgzly/android/repos/GitRepo.java b/app/src/main/java/com/orgzly/android/repos/GitRepo.java
index 83a596be8..09634a242 100644
--- a/app/src/main/java/com/orgzly/android/repos/GitRepo.java
+++ b/app/src/main/java/com/orgzly/android/repos/GitRepo.java
@@ -7,6 +7,8 @@
import android.util.Log;
import com.orgzly.BuildConfig;
+import com.orgzly.R;
+import com.orgzly.android.App;
import com.orgzly.android.BookName;
import com.orgzly.android.db.entity.Repo;
import com.orgzly.android.git.GitFileSynchronizer;
@@ -42,6 +44,7 @@
public class GitRepo implements SyncRepo, TwoWaySyncRepo {
private final static String TAG = GitRepo.class.getName();
private final long repoId;
+ private final Context context = App.getAppContext();
/**
* Used as cause when we try to clone into a non-empty directory
@@ -186,6 +189,8 @@ public boolean isAutoSyncSupported() {
public VersionedRook storeBook(File file, String fileName) throws IOException {
File destination = synchronizer.repoDirectoryFile(fileName);
+ ensureRepoPathIsNotIgnored(destination.getPath());
+
if (destination.exists()) {
synchronizer.updateAndCommitExistingFile(file, fileName);
} else {
@@ -231,7 +236,7 @@ private VersionedRook currentVersionedRook(Uri uri) {
private IgnoreNode getIgnores() throws IOException {
IgnoreNode ignores = new IgnoreNode();
- File ignoreFile = synchronizer.repoDirectoryFile(".orgzlyignore");
+ File ignoreFile = synchronizer.repoDirectoryFile(context.getString(R.string.repo_ignore_rules_file));
if (ignoreFile.exists()) {
FileInputStream in = new FileInputStream(ignoreFile);
try {
@@ -243,6 +248,14 @@ private IgnoreNode getIgnores() throws IOException {
return ignores;
}
+ private void ensureRepoPathIsNotIgnored(String filePath) throws IOException {
+ IgnoreNode ignores = getIgnores();
+ if (ignores.isIgnored(filePath, false) == IgnoreNode.MatchResult.IGNORED) {
+ throw new IOException(context.getString(R.string.error_file_matches_repo_ignore_rule,
+ context.getString(R.string.repo_ignore_rules_file)));
+ }
+ }
+
public boolean isUnchanged() throws IOException {
// Check if the current head is unchanged.
// If so, we can read all the VersionedRooks from the database.
@@ -310,6 +323,7 @@ public void delete(Uri uri) throws IOException {
public VersionedRook renameBook(Uri oldUri, String newRookName) throws IOException {
String oldFileName = oldUri.toString().replaceFirst("^/", "");
String newFileName = newRookName + ".org";
+ ensureRepoPathIsNotIgnored(newFileName);
if (synchronizer.renameFileInRepo(oldFileName, newFileName)) {
synchronizer.tryPush();
return currentVersionedRook(Uri.EMPTY.buildUpon().appendPath(newFileName).build());
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d8666b0d4..117c05927 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -766,6 +766,7 @@
Error while trying to generate the SSH key pair
Message: \n
Error: SSH key can only be unlocked from an activity
+ Repository filename matches a rule in %s
No change
diff --git a/app/src/main/res/values/strings_untranslatable.xml b/app/src/main/res/values/strings_untranslatable.xml
index 0b9f463e9..383695c12 100644
--- a/app/src/main/res/values/strings_untranslatable.xml
+++ b/app/src/main/res/values/strings_untranslatable.xml
@@ -42,6 +42,7 @@
master
-----BEGIN CERTIFICATE-----
WebDAV
+ .orgzlyignore
Lorem ipsum dolor sit amet, consectetur
Lorem *ipsum* dolor sit amet, /consectetur/