Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GitUtil {
- private static final RefSpec REF_SPEC = new RefSpec(Constants.GIT_REF_SPEC);
- private static final RefSpec REMOTE_REF_SPEC = new RefSpec(Constants.GIT_REMOTE_REF_SPEC);
- private static final CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(Constants.GIT_REMOTE_USER_NAME, Constants.GIT_REMOTE_PASSWORD);
- private static Git git;
- @Autowired
- private HibernateUtilServiceImpl hibernateUtilServiceImpl;
- @PostConstruct
- public void initGitRepository() throws Exception {
- File file = new File(Constants.GIT_REPOSITORY_MAIN_FILE_PATH);
- FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
- repositoryBuilder.addCeilingDirectory(file);
- repositoryBuilder.findGitDir(file);
- if (repositoryBuilder.getGitDir() == null) {
- git = Git.init().setDirectory(file.getParentFile()).call();
- StoredConfig config = git.getRepository().getConfig();
- config.setString("remote", "origin", "url", Constants.GIT_HSQLDB_REMOTE_REPOSTITORY_URL);
- RemoteConfig remoteConfig = new RemoteConfig(config, "remote");
- remoteConfig.addURI(new URIish(git.getRepository().getDirectory().toURI().toURL()));
- remoteConfig.update(config);
- config.save();
- } else {
- git = new Git(repositoryBuilder.build());
- }
- addUntrackedFiles(git.status().call().getUntracked(), git.getRepository());
- }
- public void commitAndPush() throws Exception {
- hibernateUtilServiceImpl.dumpDataBase();
- addUntrackedFiles(git.status().call().getUntracked(), git.getRepository());
- addChangedFiles(git.status().call().getModified(), git.getRepository());
- git.commit().setMessage("Update").call();
- git.push().setRemote("origin")
- .setCredentialsProvider(credentialsProvider)
- .setRefSpecs(REF_SPEC)
- .call();
- }
- public void pullAndMerge() throws GitAPIException, IOException {
- git.pull().call();
- hibernateUtilServiceImpl.backupDataBaseFromServer();
- }
- private void addUntrackedFiles(Collection<String> notTracked, Repository repository) throws Exception {
- if (notTracked == null || notTracked.size() == 0)
- return;
- AddCommand addCommand = git.add();
- for (String path : notTracked) {
- addCommand.addFilepattern(path);
- }
- addCommand.call();
- }
- private void addChangedFiles(Collection<String> changed, Repository repository) throws GitAPIException {
- if (changed == null || changed.size() == 0)
- return;
- AddCommand addCommand = git.add();
- for (String path : changed) {
- addCommand.addFilepattern(path);
- }
- addCommand.call();
- }
- }
- [core]
- symlinks = false
- repositoryformatversion = 0
- filemode = false
- logallrefupdates = true
- [remote "origin"]
- url = https://bitbucket.com/<my-profile>/<my-repository>.git
- [remote "remote"]
- url = file:///D:/database/.git/
- [gui]
- wmstate = zoomed
- geometry = 443x321+75+75 171 192
- org.eclipse.jgit.api.errors.TransportException: Nothing to fetch.
- at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:135)
- at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:267)
- at com.uz.laboratory.statistical.util.GitUtil.pullAndMerge(GitUtil.java:61)
- at com.uz.laboratory.statistical.controller.settings.SettingsController.updateCurrentDatabaseButtonListener(SettingsController.java:44)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
- at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
- at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
- at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
- at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
- at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
- at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
- at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
- at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
- at javafx.event.Event.fireEvent(Event.java:198)
- at javafx.scene.Node.fireEvent(Node.java:8411)
- at javafx.scene.control.Button.fire(Button.java:185)
- at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
- at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
- at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
- at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
- at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
- at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
- at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
- at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
- at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
- at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
- at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
- at javafx.event.Event.fireEvent(Event.java:198)
- at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
- at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
- at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
- at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
- at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
- at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
- at java.security.AccessController.doPrivileged(Native Method)
- at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
- at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
- at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
- at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
- at com.sun.glass.ui.View.notifyMouse(View.java:937)
- at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
- at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
- at java.lang.Thread.run(Thread.java:745)
- Caused by: org.eclipse.jgit.errors.TransportException: Nothing to fetch.
- at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1155)
- at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
- ... 65 more
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement