Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.87 KB | None | 0 0
  1. public class GitUtil {
  2.  
  3. private static final RefSpec REF_SPEC = new RefSpec(Constants.GIT_REF_SPEC);
  4. private static final RefSpec REMOTE_REF_SPEC = new RefSpec(Constants.GIT_REMOTE_REF_SPEC);
  5. private static final CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(Constants.GIT_REMOTE_USER_NAME, Constants.GIT_REMOTE_PASSWORD);
  6. private static Git git;
  7. @Autowired
  8. private HibernateUtilServiceImpl hibernateUtilServiceImpl;
  9.  
  10. @PostConstruct
  11. public void initGitRepository() throws Exception {
  12. File file = new File(Constants.GIT_REPOSITORY_MAIN_FILE_PATH);
  13. FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
  14. repositoryBuilder.addCeilingDirectory(file);
  15. repositoryBuilder.findGitDir(file);
  16. if (repositoryBuilder.getGitDir() == null) {
  17. git = Git.init().setDirectory(file.getParentFile()).call();
  18. StoredConfig config = git.getRepository().getConfig();
  19. config.setString("remote", "origin", "url", Constants.GIT_HSQLDB_REMOTE_REPOSTITORY_URL);
  20. RemoteConfig remoteConfig = new RemoteConfig(config, "remote");
  21. remoteConfig.addURI(new URIish(git.getRepository().getDirectory().toURI().toURL()));
  22. remoteConfig.update(config);
  23. config.save();
  24. } else {
  25. git = new Git(repositoryBuilder.build());
  26. }
  27. addUntrackedFiles(git.status().call().getUntracked(), git.getRepository());
  28. }
  29.  
  30. public void commitAndPush() throws Exception {
  31. hibernateUtilServiceImpl.dumpDataBase();
  32. addUntrackedFiles(git.status().call().getUntracked(), git.getRepository());
  33. addChangedFiles(git.status().call().getModified(), git.getRepository());
  34. git.commit().setMessage("Update").call();
  35. git.push().setRemote("origin")
  36. .setCredentialsProvider(credentialsProvider)
  37. .setRefSpecs(REF_SPEC)
  38. .call();
  39. }
  40.  
  41. public void pullAndMerge() throws GitAPIException, IOException {
  42. git.pull().call();
  43. hibernateUtilServiceImpl.backupDataBaseFromServer();
  44. }
  45.  
  46. private void addUntrackedFiles(Collection<String> notTracked, Repository repository) throws Exception {
  47. if (notTracked == null || notTracked.size() == 0)
  48. return;
  49. AddCommand addCommand = git.add();
  50. for (String path : notTracked) {
  51. addCommand.addFilepattern(path);
  52. }
  53. addCommand.call();
  54. }
  55.  
  56. private void addChangedFiles(Collection<String> changed, Repository repository) throws GitAPIException {
  57. if (changed == null || changed.size() == 0)
  58. return;
  59. AddCommand addCommand = git.add();
  60. for (String path : changed) {
  61. addCommand.addFilepattern(path);
  62. }
  63. addCommand.call();
  64. }
  65. }
  66.  
  67. [core]
  68. symlinks = false
  69. repositoryformatversion = 0
  70. filemode = false
  71. logallrefupdates = true
  72. [remote "origin"]
  73. url = https://bitbucket.com/<my-profile>/<my-repository>.git
  74. [remote "remote"]
  75. url = file:///D:/database/.git/
  76. [gui]
  77. wmstate = zoomed
  78. geometry = 443x321+75+75 171 192
  79.  
  80. org.eclipse.jgit.api.errors.TransportException: Nothing to fetch.
  81. at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:135)
  82. at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:267)
  83. at com.uz.laboratory.statistical.util.GitUtil.pullAndMerge(GitUtil.java:61)
  84. at com.uz.laboratory.statistical.controller.settings.SettingsController.updateCurrentDatabaseButtonListener(SettingsController.java:44)
  85. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  86. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  87. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  88. at java.lang.reflect.Method.invoke(Method.java:498)
  89. at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
  90. at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
  91. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  92. at java.lang.reflect.Method.invoke(Method.java:498)
  93. at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
  94. at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
  95. at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
  96. at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
  97. at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
  98. at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
  99. at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
  100. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
  101. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  102. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  103. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  104. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  105. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  106. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  107. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  108. at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
  109. at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
  110. at javafx.event.Event.fireEvent(Event.java:198)
  111. at javafx.scene.Node.fireEvent(Node.java:8411)
  112. at javafx.scene.control.Button.fire(Button.java:185)
  113. at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
  114. at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
  115. at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
  116. at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
  117. at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
  118. at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
  119. at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
  120. at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
  121. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
  122. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  123. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  124. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  125. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  126. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  127. at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  128. at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  129. at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
  130. at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
  131. at javafx.event.Event.fireEvent(Event.java:198)
  132. at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
  133. at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
  134. at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
  135. at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
  136. at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
  137. at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
  138. at java.security.AccessController.doPrivileged(Native Method)
  139. at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
  140. at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
  141. at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
  142. at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
  143. at com.sun.glass.ui.View.notifyMouse(View.java:937)
  144. at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  145. at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
  146. at java.lang.Thread.run(Thread.java:745)
  147. Caused by: org.eclipse.jgit.errors.TransportException: Nothing to fetch.
  148. at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1155)
  149. at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
  150. ... 65 more
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement