PageRenderTime 113ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/org/jenkinsci/plugins/gitclient/GitClient.java

https://gitlab.com/vectorci/git-client-plugin
Java | 935 lines | 115 code | 100 blank | 720 comment | 0 complexity | 589942784ce93148d53557cbb9385f55 MD5 | raw file
  1. package org.jenkinsci.plugins.gitclient;
  2. import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey;
  3. import com.cloudbees.plugins.credentials.CredentialsMatcher;
  4. import com.cloudbees.plugins.credentials.CredentialsMatchers;
  5. import com.cloudbees.plugins.credentials.common.StandardCredentials;
  6. import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
  7. import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
  8. import hudson.FilePath;
  9. import hudson.ProxyConfiguration;
  10. import hudson.model.TaskListener;
  11. import hudson.plugins.git.*;
  12. import org.eclipse.jgit.lib.ObjectId;
  13. import org.eclipse.jgit.lib.PersonIdent;
  14. import org.eclipse.jgit.lib.Repository;
  15. import org.eclipse.jgit.transport.RefSpec;
  16. import org.eclipse.jgit.transport.RemoteConfig;
  17. import org.eclipse.jgit.transport.URIish;
  18. import javax.annotation.CheckForNull;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.io.Writer;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Set;
  25. /**
  26. * Interface to Git functionality.
  27. *
  28. * <p>
  29. * Since 1.1, this interface is remotable, meaning it can be referenced from a remote closure call.
  30. *
  31. * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
  32. */
  33. public interface GitClient {
  34. /** Constant <code>verbose=Boolean.getBoolean(IGitAPI.class.getName() + ".verbose")</code> */
  35. boolean verbose = Boolean.getBoolean(IGitAPI.class.getName() + ".verbose");
  36. // If true, do not print the list of remote branches.
  37. /** Constant <code>quietRemoteBranches=Boolean.getBoolean(GitClient.class.getName() + ".quietRemoteBranches")</code> */
  38. boolean quietRemoteBranches = Boolean.getBoolean(GitClient.class.getName() + ".quietRemoteBranches");
  39. /**
  40. * The supported credential types.
  41. * @since 1.2.0
  42. */
  43. CredentialsMatcher CREDENTIALS_MATCHER = CredentialsMatchers.anyOf(
  44. CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
  45. CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
  46. // TODO does anyone use SSL client certificates with GIT?
  47. );
  48. /**
  49. * Remove all credentials from the client.
  50. *
  51. * @since 1.2.0
  52. */
  53. void clearCredentials();
  54. /**
  55. * Adds credentials to be used against a specific url.
  56. *
  57. * @param url the url for the credentials to be used against.
  58. * @param credentials the credentials to use.
  59. * @since 1.2.0
  60. */
  61. void addCredentials(String url, StandardCredentials credentials);
  62. /**
  63. * Adds credentials to be used when there are not url specific credentials defined.
  64. *
  65. * @param credentials the credentials to use.
  66. * @see #addCredentials(String, com.cloudbees.plugins.credentials.common.StandardCredentials)
  67. * @since 1.2.0
  68. */
  69. void addDefaultCredentials(StandardCredentials credentials);
  70. /**
  71. * Sets the identity of the author for future commits and merge operations.
  72. *
  73. * @param name a {@link java.lang.String} object.
  74. * @param email a {@link java.lang.String} object.
  75. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  76. */
  77. void setAuthor(String name, String email) throws GitException;
  78. /**
  79. * setAuthor.
  80. *
  81. * @param p a {@link org.eclipse.jgit.lib.PersonIdent} object.
  82. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  83. */
  84. void setAuthor(PersonIdent p) throws GitException;
  85. /**
  86. * Sets the identity of the committer for future commits and merge operations.
  87. *
  88. * @param name a {@link java.lang.String} object.
  89. * @param email a {@link java.lang.String} object.
  90. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  91. */
  92. void setCommitter(String name, String email) throws GitException;
  93. /**
  94. * setCommitter.
  95. *
  96. * @param p a {@link org.eclipse.jgit.lib.PersonIdent} object.
  97. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  98. */
  99. void setCommitter(PersonIdent p) throws GitException;
  100. /**
  101. * Expose the JGit repository this GitClient is using.
  102. * Don't forget to call {@link org.eclipse.jgit.lib.Repository#close()}, to avoid JENKINS-12188.
  103. *
  104. * @deprecated as of 1.1
  105. * This method was deprecated to make {@link org.jenkinsci.plugins.gitclient.GitClient} remotable. When called on
  106. * a proxy object, this method throws {@link java.io.NotSerializableException}.
  107. * Use {@link #withRepository(RepositoryCallback)} to pass in the closure instead.
  108. * This prevents the repository leak (JENKINS-12188), too.
  109. * @return a {@link org.eclipse.jgit.lib.Repository} object.
  110. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  111. */
  112. Repository getRepository() throws GitException;
  113. /**
  114. * Runs the computation that requires local access to {@link org.eclipse.jgit.lib.Repository}.
  115. *
  116. * @param callable the repository callback used as closure to instance
  117. * @param <T> type for the repository callback
  118. * @return a T object.
  119. * @throws java.io.IOException in case of IO error
  120. * @throws java.lang.InterruptedException if interrupted
  121. */
  122. <T> T withRepository(RepositoryCallback<T> callable) throws IOException, InterruptedException;
  123. /**
  124. * The working tree of this repository.
  125. *
  126. * @return a {@link hudson.FilePath} object.
  127. */
  128. FilePath getWorkTree();
  129. /**
  130. * init.
  131. *
  132. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  133. * @throws java.lang.InterruptedException if interrupted.
  134. */
  135. public void init() throws GitException, InterruptedException;
  136. /**
  137. * add.
  138. *
  139. * @param filePattern a {@link java.lang.String} object.
  140. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  141. * @throws java.lang.InterruptedException if interrupted.
  142. */
  143. void add(String filePattern) throws GitException, InterruptedException;
  144. /**
  145. * commit.
  146. *
  147. * @param message a {@link java.lang.String} object.
  148. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  149. * @throws java.lang.InterruptedException if interrupted.
  150. */
  151. void commit(String message) throws GitException, InterruptedException;
  152. /**
  153. * commit.
  154. *
  155. * @deprecated as of 1.1
  156. * Use {@link #setAuthor(String, String)} and {@link #setCommitter(String, String)}
  157. * then call {@link #commit(String)}
  158. * @param message a {@link java.lang.String} object.
  159. * @param author a {@link org.eclipse.jgit.lib.PersonIdent} object.
  160. * @param committer a {@link org.eclipse.jgit.lib.PersonIdent} object.
  161. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  162. * @throws java.lang.InterruptedException if interrupted.
  163. */
  164. void commit(String message, PersonIdent author, PersonIdent committer) throws GitException, InterruptedException;
  165. /**
  166. * hasGitRepo.
  167. *
  168. * @return true if this workspace has a git repository
  169. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  170. * @throws java.lang.InterruptedException if interrupted.
  171. */
  172. boolean hasGitRepo() throws GitException, InterruptedException;
  173. /**
  174. * isCommitInRepo.
  175. *
  176. * @param commit a {@link org.eclipse.jgit.lib.ObjectId} object.
  177. * @return true if commit is in repository
  178. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  179. * @throws java.lang.InterruptedException if interrupted.
  180. */
  181. boolean isCommitInRepo(ObjectId commit) throws GitException, InterruptedException;
  182. /**
  183. * From a given repository, get a remote's URL
  184. *
  185. * @param name The name of the remote (e.g. origin)
  186. * @throws hudson.plugins.git.GitException if executing the git command fails
  187. * @return a {@link java.lang.String} object.
  188. * @throws java.lang.InterruptedException if interrupted.
  189. */
  190. String getRemoteUrl(String name) throws GitException, InterruptedException;
  191. /**
  192. * For a given repository, set a remote's URL
  193. *
  194. * @param name The name of the remote (e.g. origin)
  195. * @param url The new value of the remote's URL
  196. * @throws hudson.plugins.git.GitException if executing the git command fails
  197. * @throws java.lang.InterruptedException if interrupted.
  198. */
  199. void setRemoteUrl(String name, String url) throws GitException, InterruptedException;
  200. /**
  201. * addRemoteUrl.
  202. *
  203. * @param name a {@link java.lang.String} object.
  204. * @param url a {@link java.lang.String} object.
  205. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  206. * @throws java.lang.InterruptedException if interrupted.
  207. */
  208. void addRemoteUrl(String name, String url) throws GitException, InterruptedException;
  209. /**
  210. * Checks out the specified commit/tag/branch into the workspace.
  211. * (equivalent of <tt>git checkout <em>branch</em></tt>.)
  212. *
  213. * @param ref A git object references expression (either a sha1, tag or branch)
  214. * @deprecated use {@link #checkout()} and {@link org.jenkinsci.plugins.gitclient.CheckoutCommand}
  215. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  216. * @throws java.lang.InterruptedException if interrupted.
  217. */
  218. void checkout(String ref) throws GitException, InterruptedException;
  219. /**
  220. * Creates a new branch that points to the specified ref.
  221. * (equivalent to git checkout -b <em>branch</em> <em>commit</em>)
  222. *
  223. * This will fail if the branch already exists.
  224. *
  225. * @param ref A git object references expression. For backward compatibility, <tt>null</tt> will checkout current HEAD
  226. * @param branch name of the branch to create from reference
  227. * @deprecated use {@link #checkout()} and {@link org.jenkinsci.plugins.gitclient.CheckoutCommand}
  228. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  229. * @throws java.lang.InterruptedException if interrupted.
  230. */
  231. void checkout(String ref, String branch) throws GitException, InterruptedException;
  232. /**
  233. * checkout.
  234. *
  235. * @return a {@link org.jenkinsci.plugins.gitclient.CheckoutCommand} object.
  236. */
  237. CheckoutCommand checkout();
  238. /**
  239. * Regardless of the current state of the workspace (whether there is some dirty files, etc)
  240. * and the state of the repository (whether the branch of the specified name exists or not),
  241. * when this method exits the following conditions hold:
  242. *
  243. * <ul>
  244. * <li>The branch of the specified name <em>branch</em> exists and points to the specified <em>ref</em>
  245. * <li><tt>HEAD</tt> points to <em>branch</em>. IOW, the workspace is on the specified branch.
  246. * <li>Both index and workspace are the same tree with <em>ref</em>.
  247. * (no dirty files and no staged changes, although this method will not touch untracked files
  248. * in the workspace.)
  249. * </ul>
  250. *
  251. * <p>
  252. * This method is preferred over the {@link #checkout(String, String)} family of methods, as
  253. * this method is affected far less by the current state of the repository. The <tt>checkout</tt>
  254. * methods, in their attempt to emulate the "git checkout" command line behaviour, have too many
  255. * side effects. In Jenkins, where you care a lot less about throwing away local changes and
  256. * care a lot more about resetting the workspace into a known state, methods like this is more useful.
  257. *
  258. * <p>
  259. * For compatibility reasons, the order of the parameter is different from {@link #checkout(String, String)}.
  260. *
  261. * @since 1.0.6
  262. * @param branch a {@link java.lang.String} object.
  263. * @param ref a {@link java.lang.String} object.
  264. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  265. * @throws java.lang.InterruptedException if interrupted.
  266. */
  267. void checkoutBranch(@CheckForNull String branch, String ref) throws GitException, InterruptedException;
  268. /**
  269. * Clone a remote repository
  270. *
  271. * @param url URL for remote repository to clone
  272. * @param origin upstream track name, defaults to <tt>origin</tt> by convention
  273. * @param useShallowClone option to create a shallow clone, that has some restriction but will make clone operation
  274. * @param reference (optional) reference to a local clone for faster clone operations (reduce network and local storage costs)
  275. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  276. * @throws java.lang.InterruptedException if interrupted.
  277. */
  278. void clone(String url, String origin, boolean useShallowClone, String reference) throws GitException, InterruptedException;
  279. /**
  280. * Returns a {@link org.jenkinsci.plugins.gitclient.CloneCommand} to build up the git-log invocation.
  281. *
  282. * @return a {@link org.jenkinsci.plugins.gitclient.CloneCommand} object.
  283. */
  284. CloneCommand clone_(); // can't use 'clone' as it collides with Object.clone()
  285. /**
  286. * Fetch commits from url which match any of the passed in
  287. * refspecs. Assumes <tt>remote.remoteName.url</tt> has been set.
  288. *
  289. * @deprecated use {@link #fetch_()} and configure a {@link org.jenkinsci.plugins.gitclient.FetchCommand}
  290. * @param url a {@link org.eclipse.jgit.transport.URIish} object.
  291. * @param refspecs a {@link java.util.List} object.
  292. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  293. * @throws java.lang.InterruptedException if interrupted.
  294. */
  295. void fetch(URIish url, List<RefSpec> refspecs) throws GitException, InterruptedException;
  296. /**
  297. * fetch.
  298. *
  299. * @deprecated use {@link #fetch_()} and configure a {@link org.jenkinsci.plugins.gitclient.FetchCommand}
  300. * @param remoteName a {@link java.lang.String} object.
  301. * @param refspec a {@link org.eclipse.jgit.transport.RefSpec} object.
  302. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  303. * @throws java.lang.InterruptedException if interrupted.
  304. */
  305. void fetch(String remoteName, RefSpec... refspec) throws GitException, InterruptedException;
  306. /**
  307. * fetch.
  308. *
  309. * @deprecated use {@link #fetch_()} and configure a {@link org.jenkinsci.plugins.gitclient.FetchCommand}
  310. * @param remoteName a {@link java.lang.String} object.
  311. * @param refspec a {@link org.eclipse.jgit.transport.RefSpec} object.
  312. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  313. * @throws java.lang.InterruptedException if interrupted.
  314. */
  315. void fetch(String remoteName, RefSpec refspec) throws GitException, InterruptedException;
  316. /**
  317. * fetch_.
  318. *
  319. * @return a {@link org.jenkinsci.plugins.gitclient.FetchCommand} object.
  320. */
  321. FetchCommand fetch_(); // can't use 'fetch' as legacy IGitAPI already define this method
  322. /**
  323. * push.
  324. *
  325. * @deprecated use {@link #push()} and configure a {@link org.jenkinsci.plugins.gitclient.PushCommand}
  326. * @param remoteName a {@link java.lang.String} object.
  327. * @param refspec a {@link java.lang.String} object.
  328. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  329. * @throws java.lang.InterruptedException if interrupted.
  330. */
  331. void push(String remoteName, String refspec) throws GitException, InterruptedException;
  332. /**
  333. * push.
  334. *
  335. * @deprecated use {@link #push()} and configure a {@link org.jenkinsci.plugins.gitclient.PushCommand}
  336. * @param url a {@link org.eclipse.jgit.transport.URIish} object.
  337. * @param refspec a {@link java.lang.String} object.
  338. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  339. * @throws java.lang.InterruptedException if interrupted.
  340. */
  341. void push(URIish url, String refspec) throws GitException, InterruptedException;
  342. /**
  343. * push.
  344. *
  345. * @return a {@link org.jenkinsci.plugins.gitclient.PushCommand} object.
  346. */
  347. PushCommand push();
  348. /**
  349. * merge.
  350. *
  351. * @deprecated use {@link #merge()} and configure a {@link org.jenkinsci.plugins.gitclient.MergeCommand}
  352. * @param rev a {@link org.eclipse.jgit.lib.ObjectId} object.
  353. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  354. * @throws java.lang.InterruptedException if interrupted.
  355. */
  356. void merge(ObjectId rev) throws GitException, InterruptedException;
  357. /**
  358. * merge.
  359. *
  360. * @return a {@link org.jenkinsci.plugins.gitclient.MergeCommand} object.
  361. */
  362. MergeCommand merge();
  363. /**
  364. * rebase.
  365. *
  366. * @return a {@link org.jenkinsci.plugins.gitclient.RebaseCommand} object.
  367. */
  368. RebaseCommand rebase();
  369. /**
  370. * init_.
  371. *
  372. * @return a {@link org.jenkinsci.plugins.gitclient.InitCommand} object.
  373. */
  374. InitCommand init_(); // can't use 'init' as legacy IGitAPI already define this method
  375. /**
  376. * Prune stale remote tracking branches with "git remote prune" on the specified remote.
  377. *
  378. * @param repository a {@link org.eclipse.jgit.transport.RemoteConfig} object.
  379. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  380. * @throws java.lang.InterruptedException if interrupted.
  381. */
  382. void prune(RemoteConfig repository) throws GitException, InterruptedException;
  383. /**
  384. * Fully revert working copy to a clean state, i.e. run both
  385. * <a href="https://www.kernel.org/pub/software/scm/git/docs/git-reset.html">git-reset(1) --hard</a> then
  386. * <a href="https://www.kernel.org/pub/software/scm/git/docs/git-clean.html">git-clean(1)</a> for working copy to
  387. * match a fresh clone.
  388. *
  389. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  390. * @throws java.lang.InterruptedException if interrupted.
  391. */
  392. void clean() throws GitException, InterruptedException;
  393. // --- manage branches
  394. /**
  395. * branch.
  396. *
  397. * @param name a {@link java.lang.String} object.
  398. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  399. * @throws java.lang.InterruptedException if interrupted.
  400. */
  401. void branch(String name) throws GitException, InterruptedException;
  402. /**
  403. * (force) delete a branch.
  404. *
  405. * @param name a {@link java.lang.String} object.
  406. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  407. * @throws java.lang.InterruptedException if interrupted.
  408. */
  409. void deleteBranch(String name) throws GitException, InterruptedException;
  410. /**
  411. * getBranches.
  412. *
  413. * @return a {@link java.util.Set} object.
  414. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  415. * @throws java.lang.InterruptedException if interrupted.
  416. */
  417. Set<Branch> getBranches() throws GitException, InterruptedException;
  418. /**
  419. * getRemoteBranches.
  420. *
  421. * @return a {@link java.util.Set} object.
  422. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  423. * @throws java.lang.InterruptedException if interrupted.
  424. */
  425. Set<Branch> getRemoteBranches() throws GitException, InterruptedException;
  426. // --- manage tags
  427. /**
  428. * Create (or update) a tag. If tag already exist it gets updated (equivalent to <tt>git tag --force</tt>)
  429. *
  430. * @param tagName a {@link java.lang.String} object.
  431. * @param comment a {@link java.lang.String} object.
  432. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  433. * @throws java.lang.InterruptedException if interrupted.
  434. */
  435. void tag(String tagName, String comment) throws GitException, InterruptedException;
  436. /**
  437. * tagExists.
  438. *
  439. * @param tagName a {@link java.lang.String} object.
  440. * @return true if tag exists in repository
  441. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  442. * @throws java.lang.InterruptedException if interrupted.
  443. */
  444. boolean tagExists(String tagName) throws GitException, InterruptedException;
  445. /**
  446. * getTagMessage.
  447. *
  448. * @param tagName a {@link java.lang.String} object.
  449. * @return a {@link java.lang.String} object.
  450. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  451. * @throws java.lang.InterruptedException if interrupted.
  452. */
  453. String getTagMessage(String tagName) throws GitException, InterruptedException;
  454. /**
  455. * deleteTag.
  456. *
  457. * @param tagName a {@link java.lang.String} object.
  458. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  459. * @throws java.lang.InterruptedException if interrupted.
  460. */
  461. void deleteTag(String tagName) throws GitException, InterruptedException;
  462. /**
  463. * getTagNames.
  464. *
  465. * @param tagPattern a {@link java.lang.String} object.
  466. * @return a {@link java.util.Set} object.
  467. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  468. * @throws java.lang.InterruptedException if interrupted.
  469. */
  470. Set<String> getTagNames(String tagPattern) throws GitException, InterruptedException;
  471. /**
  472. * getRemoteTagNames.
  473. *
  474. * @param tagPattern a {@link java.lang.String} object.
  475. * @return a {@link java.util.Set} object.
  476. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  477. * @throws java.lang.InterruptedException if interrupted.
  478. */
  479. Set<String> getRemoteTagNames(String tagPattern) throws GitException, InterruptedException;
  480. // --- manage refs
  481. /**
  482. * Create (or update) a ref. The ref will reference HEAD (equivalent to <tt>git update-ref ... HEAD</tt>).
  483. *
  484. * @param refName the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.
  485. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  486. * @throws java.lang.InterruptedException if interrupted.
  487. */
  488. void ref(String refName) throws GitException, InterruptedException;
  489. /**
  490. * Check if a ref exists. Equivalent to comparing the return code of <tt>git show-ref</tt> to zero.
  491. *
  492. * @param refName the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.
  493. * @return True if the ref exists, false otherwse.
  494. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  495. * @throws java.lang.InterruptedException if interrupted.
  496. */
  497. boolean refExists(String refName) throws GitException, InterruptedException;
  498. /**
  499. * Deletes a ref. Has no effect if the ref does not exist, equivalent to <tt>git update-ref -d</tt>.
  500. *
  501. * @param refName the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.
  502. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  503. * @throws java.lang.InterruptedException if interrupted.
  504. */
  505. void deleteRef(String refName) throws GitException, InterruptedException;
  506. /**
  507. * List refs with the given prefix. Equivalent to <tt>git for-each-ref --format="%(refname)"</tt>.
  508. *
  509. * @param refPrefix the literal prefix any ref returned will have. The empty string implies all.
  510. * @return a set of refs, each beginning with the given prefix. Empty if none.
  511. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  512. * @throws java.lang.InterruptedException if interrupted.
  513. */
  514. Set<String> getRefNames(String refPrefix) throws GitException, InterruptedException;
  515. // --- lookup revision
  516. /**
  517. * getHeadRev.
  518. *
  519. * @param url a {@link java.lang.String} object.
  520. * @return a {@link java.util.Map} object.
  521. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  522. * @throws java.lang.InterruptedException if interrupted.
  523. */
  524. Map<String, ObjectId> getHeadRev(String url) throws GitException, InterruptedException;
  525. /**
  526. * getHeadRev.
  527. *
  528. * @param remoteRepoUrl a {@link java.lang.String} object.
  529. * @param branch a {@link java.lang.String} object.
  530. * @return a {@link org.eclipse.jgit.lib.ObjectId} object.
  531. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  532. * @throws java.lang.InterruptedException if interrupted.
  533. */
  534. ObjectId getHeadRev(String remoteRepoUrl, String branch) throws GitException, InterruptedException;
  535. /**
  536. * List references in a remote repository. Equivalent to <tt>git ls-remote [--heads] [--tags] &lt;repository&gt; [&lt;refs&gt;]</tt>.
  537. *
  538. * @param remoteRepoUrl
  539. * Remote repository URL.
  540. * @param pattern
  541. * Only references matching the given pattern are displayed.
  542. * @param headsOnly
  543. * Limit to only refs/heads.
  544. * @param tagsOnly
  545. * Limit to only refs/tags.
  546. * headsOnly and tagsOnly are not mutually exclusive;
  547. * when both are true, references stored in refs/heads and refs/tags are displayed.
  548. * @return a map of references name and its commit hash. Empty if none.
  549. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  550. * @throws java.lang.InterruptedException if interrupted.
  551. */
  552. Map<String, ObjectId> getRemoteReferences(String remoteRepoUrl, String pattern, boolean headsOnly, boolean tagsOnly) throws GitException, InterruptedException;
  553. /**
  554. * Retrieve commit object that is direct child for <tt>revName</tt> revision reference.
  555. *
  556. * @param revName a commit sha1 or tag/branch refname
  557. * @throws hudson.plugins.git.GitException when no such commit / revName is found in repository.
  558. * @return a {@link org.eclipse.jgit.lib.ObjectId} object.
  559. * @throws java.lang.InterruptedException if interrupted.
  560. */
  561. ObjectId revParse(String revName) throws GitException, InterruptedException;
  562. /**
  563. * revList_.
  564. *
  565. * @return a {@link org.jenkinsci.plugins.gitclient.RevListCommand} object.
  566. */
  567. RevListCommand revList_();
  568. /**
  569. * revListAll.
  570. *
  571. * @return a {@link java.util.List} object.
  572. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  573. * @throws java.lang.InterruptedException if interrupted.
  574. */
  575. List<ObjectId> revListAll() throws GitException, InterruptedException;
  576. /**
  577. * revList.
  578. *
  579. * @param ref a {@link java.lang.String} object.
  580. * @return a {@link java.util.List} object.
  581. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  582. * @throws java.lang.InterruptedException if interrupted.
  583. */
  584. List<ObjectId> revList(String ref) throws GitException, InterruptedException;
  585. // --- submodules
  586. /**
  587. * subGit.
  588. *
  589. * @return a IGitAPI implementation to manage git submodule repository
  590. * @param subdir a {@link java.lang.String} object.
  591. */
  592. GitClient subGit(String subdir);
  593. /**
  594. * Returns true if the repository has Git submodules.
  595. *
  596. * @return true if this repository has submodules
  597. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  598. * @throws java.lang.InterruptedException if interrupted.
  599. */
  600. boolean hasGitModules() throws GitException, InterruptedException;
  601. /**
  602. * Finds all the submodule references in this repository at the specified tree.
  603. *
  604. * @return never null.
  605. * @param treeIsh a {@link java.lang.String} object.
  606. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  607. * @throws java.lang.InterruptedException if interrupted.
  608. */
  609. List<IndexEntry> getSubmodules( String treeIsh ) throws GitException, InterruptedException;
  610. /**
  611. * Create a submodule in subdir child directory for remote repository
  612. *
  613. * @param remoteURL a {@link java.lang.String} object.
  614. * @param subdir a {@link java.lang.String} object.
  615. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  616. * @throws java.lang.InterruptedException if interrupted.
  617. */
  618. void addSubmodule(String remoteURL, String subdir) throws GitException, InterruptedException;
  619. /**
  620. * Run submodule update optionally recursively on all submodules
  621. * (equivalent of <tt>git submodule update <em>--recursive</em></tt>.)
  622. *
  623. * @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
  624. * @param recursive a boolean.
  625. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  626. * @throws java.lang.InterruptedException if interrupted.
  627. */
  628. void submoduleUpdate(boolean recursive) throws GitException, InterruptedException;
  629. /**
  630. * Run submodule update optionally recursively on all submodules, with a specific
  631. * reference passed to git clone if needing to --init.
  632. * (equivalent of <tt>git submodule update <em>--recursive</em> <em>--reference 'reference'</em></tt>.)
  633. *
  634. * @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
  635. * @param recursive a boolean.
  636. * @param reference a {@link java.lang.String} object.
  637. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  638. * @throws java.lang.InterruptedException if interrupted.
  639. */
  640. void submoduleUpdate(boolean recursive, String reference) throws GitException, InterruptedException;
  641. /**
  642. * Run submodule update optionally recursively on all submodules, optionally with remoteTracking submodules
  643. * (equivalent of <tt>git submodule update <em>--recursive</em> <em>--remote</em></tt>.)
  644. *
  645. * @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
  646. * @param recursive a boolean.
  647. * @param remoteTracking a boolean.
  648. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  649. * @throws java.lang.InterruptedException if interrupted.
  650. */
  651. void submoduleUpdate(boolean recursive, boolean remoteTracking) throws GitException, InterruptedException;
  652. /**
  653. * Run submodule update optionally recursively on all submodules, optionally with remoteTracking, with a specific
  654. * reference passed to git clone if needing to --init.
  655. * (equivalent of <tt>git submodule update <em>--recursive</em> <em>--remote</em> <em>--reference 'reference'</em></tt>.)
  656. *
  657. * @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
  658. * @param recursive a boolean.
  659. * @param remoteTracking a boolean.
  660. * @param reference a {@link java.lang.String} object.
  661. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  662. * @throws java.lang.InterruptedException if interrupted.
  663. */
  664. void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference) throws GitException, InterruptedException;
  665. /**
  666. * submoduleUpdate.
  667. *
  668. * @return a {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand} object.
  669. */
  670. SubmoduleUpdateCommand submoduleUpdate();
  671. /**
  672. * submoduleClean.
  673. *
  674. * @param recursive a boolean.
  675. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  676. * @throws java.lang.InterruptedException if interrupted.
  677. */
  678. void submoduleClean(boolean recursive) throws GitException, InterruptedException;
  679. /**
  680. * submoduleInit.
  681. *
  682. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  683. * @throws java.lang.InterruptedException if interrupted.
  684. */
  685. void submoduleInit() throws GitException, InterruptedException;
  686. /**
  687. * Set up submodule URLs so that they correspond to the remote pertaining to
  688. * the revision that has been checked out.
  689. *
  690. * @param rev a {@link hudson.plugins.git.Revision} object.
  691. * @param listener a {@link hudson.model.TaskListener} object.
  692. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  693. * @throws java.lang.InterruptedException if interrupted.
  694. */
  695. void setupSubmoduleUrls( Revision rev, TaskListener listener ) throws GitException, InterruptedException;
  696. // --- commit log and notes
  697. /**
  698. * changelog.
  699. *
  700. * @deprecated use {@link #changelog(String, String, Writer)}
  701. * @param revFrom a {@link java.lang.String} object.
  702. * @param revTo a {@link java.lang.String} object.
  703. * @param os a {@link java.io.OutputStream} object.
  704. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  705. * @throws java.lang.InterruptedException if interrupted.
  706. */
  707. void changelog(String revFrom, String revTo, OutputStream os) throws GitException, InterruptedException;
  708. /**
  709. * Adds the changelog entries for commits in the range revFrom..revTo.
  710. *
  711. * This is just a short cut for calling {@link #changelog()} with appropriate parameters.
  712. *
  713. * @param revFrom a {@link java.lang.String} object.
  714. * @param revTo a {@link java.lang.String} object.
  715. * @param os a {@link java.io.Writer} object.
  716. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  717. * @throws java.lang.InterruptedException if interrupted.
  718. */
  719. void changelog(String revFrom, String revTo, Writer os) throws GitException, InterruptedException;
  720. /**
  721. * Returns a {@link org.jenkinsci.plugins.gitclient.ChangelogCommand} to build up the git-log invocation.
  722. *
  723. * @return a {@link org.jenkinsci.plugins.gitclient.ChangelogCommand} object.
  724. */
  725. ChangelogCommand changelog();
  726. /**
  727. * Appends to an existing git-note on the current HEAD commit.
  728. *
  729. * If a note doesn't exist, it works just like {@link #addNote(String, String)}
  730. *
  731. * @param note
  732. * Content of the note.
  733. * @param namespace
  734. * If unqualified, interpreted as "refs/notes/NAMESPACE" just like cgit.
  735. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  736. * @throws java.lang.InterruptedException if interrupted.
  737. */
  738. void appendNote(String note, String namespace ) throws GitException, InterruptedException;
  739. /**
  740. * Adds a new git-note on the current HEAD commit.
  741. *
  742. * @param note
  743. * Content of the note.
  744. * @param namespace
  745. * If unqualified, interpreted as "refs/notes/NAMESPACE" just like cgit.
  746. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  747. * @throws java.lang.InterruptedException if interrupted.
  748. */
  749. void addNote(String note, String namespace ) throws GitException, InterruptedException;
  750. /**
  751. * showRevision.
  752. *
  753. * @param r a {@link org.eclipse.jgit.lib.ObjectId} object.
  754. * @return a {@link java.util.List} object.
  755. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  756. * @throws java.lang.InterruptedException if interrupted.
  757. */
  758. public List<String> showRevision(ObjectId r) throws GitException, InterruptedException;
  759. /**
  760. * Given a Revision, show it as if it were an entry from git whatchanged, so that it
  761. * can be parsed by GitChangeLogParser.
  762. *
  763. * <p>
  764. * Changes are computed on the [from..to] range. If {@code from} is null, this prints
  765. * just one commit that {@code to} represents.
  766. *
  767. * <p>
  768. * For merge commit, this method reports one diff per each parent. This makes this method
  769. * behave differently from {@link #changelog()}.
  770. *
  771. * @return The git show output, in <tt>raw</tt> format.
  772. * @param from a {@link org.eclipse.jgit.lib.ObjectId} object.
  773. * @param to a {@link org.eclipse.jgit.lib.ObjectId} object.
  774. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  775. * @throws java.lang.InterruptedException if interrupted.
  776. */
  777. List<String> showRevision(ObjectId from, ObjectId to) throws GitException, InterruptedException;
  778. /**
  779. * Given a Revision, show it as if it were an entry from git whatchanged, so that it
  780. * can be parsed by GitChangeLogParser.
  781. *
  782. * <p>
  783. * If useRawOutput is true, the '--raw' option will include commit file information to be passed to the
  784. * GitChangeLogParser.
  785. *
  786. * <p>
  787. * Changes are computed on the [from..to] range. If {@code from} is null, this prints
  788. * just one commit that {@code to} represents.
  789. *
  790. * <p>
  791. * For merge commit, this method reports one diff per each parent. This makes this method
  792. * behave differently from {@link #changelog()}.
  793. *
  794. * @return The git show output, in <tt>raw</tt> format.
  795. * @param from a {@link org.eclipse.jgit.lib.ObjectId} object.
  796. * @param to a {@link org.eclipse.jgit.lib.ObjectId} object.
  797. * @param useRawOutput a {java.lang.Boolean} object.
  798. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  799. * @throws java.lang.InterruptedException if interrupted.
  800. */
  801. List<String> showRevision(ObjectId from, ObjectId to, Boolean useRawOutput) throws GitException, InterruptedException;
  802. /**
  803. * Equivalent of "git-describe --tags".
  804. *
  805. * Find a nearby tag (including unannotated ones) and come up with a short identifier to describe the tag.
  806. *
  807. * @param commitIsh a {@link java.lang.String} object.
  808. * @return a {@link java.lang.String} object.
  809. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  810. * @throws java.lang.InterruptedException if interrupted.
  811. */
  812. String describe(String commitIsh) throws GitException, InterruptedException;
  813. /**
  814. * setCredentials.
  815. *
  816. * @param cred a {@link com.cloudbees.plugins.credentials.common.StandardUsernameCredentials} object.
  817. */
  818. void setCredentials(StandardUsernameCredentials cred);
  819. /**
  820. * setProxy.
  821. *
  822. * @param proxy a {@link hudson.ProxyConfiguration} object.
  823. */
  824. void setProxy(ProxyConfiguration proxy);
  825. /**
  826. * Find all the branches that include the given commit.
  827. *
  828. * @param revspec commit id to query for
  829. * @param allBranches whether remote branches should be also queried (<code>true</code>) or not (<code>false</code>)
  830. * @return list of branches the specified commit belongs to
  831. * @throws hudson.plugins.git.GitException on Git exceptions
  832. * @throws java.lang.InterruptedException on thread interruption
  833. */
  834. List<Branch> getBranchesContaining(String revspec, boolean allBranches) throws GitException, InterruptedException;
  835. }