Skip to content

Commit 6ab17d0

Browse files
committed
Resolve conflicts
1 parent 3cec80d commit 6ab17d0

File tree

13 files changed

+70
-40
lines changed

13 files changed

+70
-40
lines changed

jabgui/src/main/java/org/jabref/gui/actions/StandardActions.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ public enum StandardActions implements Action {
217217
GROUP_SUBGROUP_RENAME(Localization.lang("Rename subgroup"), KeyBinding.GROUP_SUBGROUP_RENAME),
218218
GROUP_ENTRIES_REMOVE(Localization.lang("Remove selected entries from this group")),
219219

220-
CLEAR_EMBEDDINGS_CACHE(Localization.lang("Clear embeddings cache"));
220+
CLEAR_EMBEDDINGS_CACHE(Localization.lang("Clear embeddings cache")),
221+
222+
GIT(Localization.lang("Git"), IconTheme.JabRefIcons.GIT_SYNC),
223+
GIT_PULL(Localization.lang("Pull")),
224+
GIT_PUSH(Localization.lang("Push")),
225+
GIT_COMMIT(Localization.lang("Commit")),
226+
GIT_SHARE(Localization.lang("Share this library to GitHub"));
227+
221228

222229
private String text;
223230
private final String description;

jabgui/src/main/java/org/jabref/gui/icon/IconTheme.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public enum JabRefIcons implements JabRefIcon {
370370
CONSISTENCY_OPTIONAL_FIELD(MaterialDesignC.CIRCLE_OUTLINE),
371371
CONSISTENCY_UNKNOWN_FIELD(MaterialDesignH.HELP),
372372
ABSOLUTE_PATH(MaterialDesignF.FAMILY_TREE),
373+
GIT_SYNC(MaterialDesignG.GIT),
373374
RELATIVE_PATH(MaterialDesignF.FILE_TREE_OUTLINE),
374375
SHORTEN_DOI(MaterialDesignA.ARROW_COLLAPSE_HORIZONTAL);
375376

jabgui/src/main/java/org/jabref/gui/slr/ExistingStudySearchAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.jabref.gui.actions.ActionHelper;
1111
import org.jabref.gui.actions.SimpleCommand;
1212
import org.jabref.gui.importer.actions.OpenDatabaseAction;
13+
import org.jabref.logic.JabRefException;
1314
import org.jabref.logic.crawler.Crawler;
1415
import org.jabref.logic.git.SlrGitHandler;
1516
import org.jabref.logic.importer.ParseException;
@@ -116,7 +117,7 @@ protected void crawl() {
116117
preferences,
117118
new BibEntryTypesManager(),
118119
fileUpdateMonitor);
119-
} catch (IOException | ParseException e) {
120+
} catch (IOException | ParseException | JabRefException e) {
120121
LOGGER.error("Error during reading of study definition file.", e);
121122
dialogService.showErrorDialogAndWait(Localization.lang("Error during reading of study definition file."), e);
122123
return;

jablib/src/main/java/org/jabref/logic/crawler/Crawler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.nio.file.Path;
55
import java.util.List;
66

7+
import org.jabref.logic.JabRefException;
78
import org.jabref.logic.exporter.SaveException;
89
import org.jabref.logic.git.SlrGitHandler;
910
import org.jabref.logic.importer.ParseException;
@@ -36,7 +37,7 @@ public Crawler(Path studyRepositoryRoot,
3637
SlrGitHandler gitHandler,
3738
CliPreferences preferences,
3839
BibEntryTypesManager bibEntryTypesManager,
39-
FileUpdateMonitor fileUpdateMonitor) throws IllegalArgumentException, IOException, ParseException {
40+
FileUpdateMonitor fileUpdateMonitor) throws IllegalArgumentException, IOException, ParseException, JabRefException {
4041
this.studyRepository = new StudyRepository(
4142
studyRepositoryRoot,
4243
gitHandler,
@@ -66,7 +67,7 @@ public Crawler(Path studyRepositoryRoot,
6667
*
6768
* @throws IOException Thrown if a problem occurred during the persistence of the result.
6869
*/
69-
public void performCrawl() throws IOException, GitAPIException, SaveException {
70+
public void performCrawl() throws IOException, GitAPIException, SaveException, JabRefException {
7071
List<QueryResult> results = studyFetcher.crawl();
7172
studyRepository.persist(results);
7273
}

jablib/src/main/java/org/jabref/logic/crawler/StudyRepository.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.regex.Pattern;
1212
import java.util.stream.Collectors;
1313

14+
import org.jabref.logic.JabRefException;
1415
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
1516
import org.jabref.logic.database.DatabaseMerger;
1617
import org.jabref.logic.exporter.AtomicFileWriter;
@@ -84,7 +85,7 @@ public StudyRepository(Path pathToRepository,
8485
SlrGitHandler gitHandler,
8586
CliPreferences preferences,
8687
FileUpdateMonitor fileUpdateMonitor,
87-
BibEntryTypesManager bibEntryTypesManager) throws IOException {
88+
BibEntryTypesManager bibEntryTypesManager) throws IOException, JabRefException {
8889
this.repositoryPath = pathToRepository;
8990
this.gitHandler = gitHandler;
9091
this.preferences = preferences;
@@ -218,7 +219,7 @@ public Study getStudy() {
218219
* <li>Update the remote tracking branches of the work and search branch</li>
219220
* </ol>
220221
*/
221-
public void persist(List<QueryResult> crawlResults) throws IOException, GitAPIException, SaveException {
222+
public void persist(List<QueryResult> crawlResults) throws IOException, GitAPIException, SaveException, JabRefException {
222223
updateWorkAndSearchBranch();
223224

224225
gitHandler.checkoutBranch(SEARCH_BRANCH);
@@ -237,14 +238,16 @@ public void persist(List<QueryResult> crawlResults) throws IOException, GitAPIEx
237238
updateRemoteSearchAndWorkBranch();
238239
} catch (GitAPIException e) {
239240
LOGGER.error("Updating remote repository failed", e);
241+
} catch (JabRefException e) {
242+
LOGGER.error("Missing Git credentials", e);
240243
}
241244
}
242245

243246
/**
244247
* Update the remote tracking branches of the work and search branches
245248
* The currently checked out branch is not changed if the method is executed successfully
246249
*/
247-
private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIException {
250+
private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIException, JabRefException {
248251
String currentBranch = gitHandler.getCurrentlyCheckedOutBranch();
249252

250253
// update remote search branch
@@ -262,7 +265,7 @@ private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIExcepti
262265
* Updates the local work and search branches with changes from their tracking remote branches
263266
* The currently checked out branch is not changed if the method is executed successfully
264267
*/
265-
private void updateWorkAndSearchBranch() throws IOException, GitAPIException {
268+
private void updateWorkAndSearchBranch() throws IOException, GitAPIException, JabRefException {
266269
String currentBranch = gitHandler.getCurrentlyCheckedOutBranch();
267270

268271
// update search branch

jablib/src/main/java/org/jabref/logic/git/GitHandler.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
import java.nio.file.Path;
88
import java.util.Optional;
99

10+
import org.jabref.logic.JabRefException;
1011
import org.jabref.logic.git.prefs.GitPreferences;
1112

1213
import org.eclipse.jgit.api.Git;
1314
import org.eclipse.jgit.api.RmCommand;
1415
import org.eclipse.jgit.api.Status;
1516
import org.eclipse.jgit.api.errors.GitAPIException;
1617
import org.eclipse.jgit.lib.Ref;
18+
import org.eclipse.jgit.lib.Repository;
1719
import org.eclipse.jgit.lib.RepositoryState;
1820
import org.eclipse.jgit.merge.MergeStrategy;
21+
import org.eclipse.jgit.revwalk.RevCommit;
1922
import org.eclipse.jgit.transport.CredentialsProvider;
2023
import org.eclipse.jgit.transport.RefSpec;
2124
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
@@ -70,9 +73,9 @@ public void initIfNeeded() {
7073
}
7174
}
7275

73-
private CredentialsProvider resolveCredentialsOrLoad() throws IOException {
76+
private Optional<CredentialsProvider> resolveCredentialsOrLoad() throws JabRefException {
7477
if (credentialsProvider != null) {
75-
return credentialsProvider;
78+
return Optional.of(credentialsProvider);
7679
}
7780

7881
String user = Optional.ofNullable(System.getenv("GIT_EMAIL")).orElse("");
@@ -87,11 +90,11 @@ private CredentialsProvider resolveCredentialsOrLoad() throws IOException {
8790
}
8891

8992
if (user.isBlank() || password.isBlank()) {
90-
throw new IOException("Missing Git credentials (username, password or PAT).");
93+
return Optional.empty();
9194
}
9295

9396
this.credentialsProvider = new UsernamePasswordCredentialsProvider(user, password);
94-
return this.credentialsProvider;
97+
return Optional.of(this.credentialsProvider);
9598
}
9699

97100
public void setCredentials(String username, String pat) {
@@ -227,18 +230,19 @@ public void mergeBranches(String targetBranch, String sourceBranch, MergeStrateg
227230
* Pushes all commits made to the branch that is tracked by the currently checked out branch.
228231
* If pushing to remote fails, it fails silently.
229232
*/
230-
public void pushCommitsToRemoteRepository() throws IOException, GitAPIException {
231-
CredentialsProvider provider = resolveCredentialsOrLoad();
233+
public void pushCommitsToRemoteRepository() throws IOException, GitAPIException, JabRefException {
234+
CredentialsProvider provider = resolveCredentialsOrLoad().orElseThrow(() -> new IOException("Missing Git credentials (username and Personal Access Token)."));
235+
232236
try (Git git = Git.open(this.repositoryPathAsFile)) {
233237
git.push()
234238
.setCredentialsProvider(provider)
235239
.call();
236240
}
237241
}
238242

239-
public void pushCurrentBranchCreatingUpstream() throws IOException, GitAPIException {
243+
public void pushCurrentBranchCreatingUpstream() throws IOException, GitAPIException, JabRefException {
240244
try (Git git = open()) {
241-
CredentialsProvider provider = resolveCredentialsOrLoad();
245+
CredentialsProvider provider = resolveCredentialsOrLoad().orElseThrow(() -> new IOException("Missing Git credentials (username and Personal Access Token)."));
242246
String branch = git.getRepository().getBranch();
243247
git.push()
244248
.setRemote("origin")
@@ -248,8 +252,8 @@ public void pushCurrentBranchCreatingUpstream() throws IOException, GitAPIExcept
248252
}
249253
}
250254

251-
public void pullOnCurrentBranch() throws IOException {
252-
CredentialsProvider provider = resolveCredentialsOrLoad();
255+
public void pullOnCurrentBranch() throws IOException, JabRefException {
256+
CredentialsProvider provider = resolveCredentialsOrLoad().orElseThrow(() -> new IOException("Missing Git credentials (username and Personal Access Token)."));
253257
try (Git git = Git.open(this.repositoryPathAsFile)) {
254258
try {
255259
git.pull()
@@ -267,8 +271,8 @@ public String getCurrentlyCheckedOutBranch() throws IOException {
267271
}
268272
}
269273

270-
public void fetchOnCurrentBranch() throws IOException {
271-
CredentialsProvider provider = resolveCredentialsOrLoad();
274+
public void fetchOnCurrentBranch() throws IOException, JabRefException {
275+
CredentialsProvider provider = resolveCredentialsOrLoad().orElseThrow(() -> new IOException("Missing Git credentials (username and Personal Access Token)."));
272276
try (Git git = Git.open(this.repositoryPathAsFile)) {
273277
git.fetch()
274278
.setCredentialsProvider(provider)

jablib/src/main/java/org/jabref/logic/git/prefs/GitPreferences.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.UnsupportedEncodingException;
44
import java.security.GeneralSecurityException;
5+
import java.util.Arrays;
56
import java.util.Optional;
67
import java.util.prefs.Preferences;
78

@@ -26,13 +27,18 @@ public GitPreferences() {
2627
}
2728

2829
public void savePersonalAccessToken(String pat, String username) {
30+
char[] patChars = pat != null ? pat.toCharArray() : new char[0];
31+
final String encrypted;
2932
try {
30-
setUsername(username);
31-
String encrypted = new Password(pat.toCharArray(), username).encrypt();
32-
setPat(encrypted);
33+
encrypted = new Password(patChars, username).encrypt();
3334
} catch (GeneralSecurityException | UnsupportedEncodingException e) {
34-
LOGGER.error("Failed to encrypt and store GitHub PAT", e);
35+
LOGGER.error("Failed to encrypt PAT", e);
36+
return;
37+
} finally {
38+
Arrays.fill(patChars, '\0');
3539
}
40+
setUsername(username);
41+
setPat(encrypted);
3642
}
3743

3844
public Optional<String> getPersonalAccessToken() {

jablib/src/main/java/org/jabref/logic/git/status/GitStatusChecker.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.nio.file.Path;
55
import java.util.Optional;
66

7+
import org.jabref.logic.JabRefException;
78
import org.jabref.logic.git.GitHandler;
89
import org.jabref.logic.git.io.GitRevisionLocator;
910

@@ -87,12 +88,8 @@ public static GitStatusSnapshot checkStatus(Path anyPathInsideRepo) {
8788
return checkStatus(handlerOpt.get());
8889
}
8990

90-
public static GitStatusSnapshot checkStatusAndFetch(GitHandler gitHandler) {
91-
try {
92-
gitHandler.fetchOnCurrentBranch();
93-
} catch (IOException e) {
94-
LOGGER.warn("Failed to fetch before checking status", e);
95-
}
91+
public static GitStatusSnapshot checkStatusAndFetch(GitHandler gitHandler) throws IOException, JabRefException {
92+
gitHandler.fetchOnCurrentBranch();
9693
return checkStatus(gitHandler);
9794
}
9895

jablib/src/main/resources/l10n/JabRef_en.properties

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,7 +3212,6 @@ GitHub\ Share=GitHub Share
32123212
GitHub\ repository\ URL\ is\ required=GitHub repository URL is required
32133213
GitHub\ username\ is\ required=GitHub username is required
32143214
Merged\ and\ updated.=Merged and updated.
3215-
Need\ help?=Need help?
32163215
Nothing\ to\ commit.=Nothing to commit.
32173216
Nothing\ to\ push.\ Local\ branch\ is\ up\ to\ date.=Nothing to push. Local branch is up to date.
32183217
Personal\ Access\ Token\ is\ required\ to\ push=Personal Access Token is required to push
@@ -3246,5 +3245,9 @@ Share=Share
32463245
Unexpected\ error\:\ %0=Unexpected error: %0
32473246
Create\ an\ empty\ repository\ on\ GitHub,\ then\ copy\ the\ HTTPS\ URL\ (ends\ with\ .git).\ Click\ to\ open\ GitHub.=Create an empty repository on GitHub, then copy the HTTPS URL (ends with .git). Click to open GitHub.
32483247
PAT\ with\ repo\ access=PAT with repo access
3249-
Tip\:\ Create\ an\ empty\ repository\ on\ GitHub,\ then\ paste\ its\ HTTPS\ URL\ here\ (e.g.,\ https\://github.com/owner/repo.git).\ If\ you\ already\ have\ one,\ copy\ the\ HTTPS\ URL\ from\ the\ Code\ menu.=Tip: Create an empty repository on GitHub, then paste its HTTPS URL here (e.g., https://github.com/owner/repo.git). If you already have one, copy the HTTPS URL from the Code menu.
32503248
Your\ GitHub\ username=Your GitHub username
3249+
Cannot\ reach\ remote=Cannot reach remote
3250+
Create\ commit\ failed=Create commit failed
3251+
Local=Local
3252+
Missing\ Git\ credentials=Missing Git credentials
3253+
Remote=Remote

jablib/src/test/java/org/jabref/logic/crawler/CrawlerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import javafx.collections.FXCollections;
1111

12+
import org.jabref.logic.JabRefException;
1213
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
1314
import org.jabref.logic.citationkeypattern.GlobalCitationKeyPatterns;
1415
import org.jabref.logic.exporter.SaveConfiguration;
@@ -106,7 +107,7 @@ private void setUpTestStudyDefinitionFile() throws URISyntaxException {
106107
}
107108

108109
@Test
109-
void whetherAllFilesAreCreated() throws IOException, ParseException, GitAPIException, SaveException {
110+
void whetherAllFilesAreCreated() throws IOException, ParseException, GitAPIException, SaveException, JabRefException {
110111
Crawler testCrawler = new Crawler(getPathToStudyDefinitionFile(),
111112
gitHandler,
112113
preferences,

0 commit comments

Comments
 (0)