aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java
Commit message (Collapse)AuthorAgeFilesLines
* Remove deprecated StashApplyCommand#setApplyUntracked methodMatthias Sohn2024-09-031-13/+0
| | | | Change-Id: I23e3ed3259edad3a22b59cca938f041b39ebf0cb
* Remove deprecated StashApplyCommand#setApplyIndex methodMatthias Sohn2024-09-031-12/+0
| | | | Change-Id: I2183285f6ccba1b62a318e711f2451df5d083ca1
* Checkout: better directory handlingThomas Wolf2023-09-031-12/+11
| | | | | | | | | | | | | | | | | | | | When checking out a file into the working tree ensure that all parent directories of the file below the working tree root are actually directories and do exist before we try to create the file. When multiple files are to be checked out (or even a whole tree), this may check the same directories over and over again. Asking the file system every time for file attributes is a potentially expensive operation. As a remedy, introduce an in-memory cache of directory states for a particular check-out operation. Apply the same fix also in the ResolveMerger, which may also check out files, and also in the PatchApplier. In PatchApplier, also validate paths. Change-Id: Ie12864c54c9f901a2ccee7caddec73027f353111 Signed-off-by: Thomas Wolf <twolf@apache.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* DirCacheCheckout: load WorkingTreeOptions only onceThomas Wolf2022-08-141-3/+6
| | | | | | | | | | | | | | | | Previous code loaded the WorkingTreeOptions afresh for every single file being checked out. This checked the git config (all three files, repo, user and system config) for having been modified every time. These checks can be costly, for instance on Windows, or if one of the three config files is not on a local disk, or on an otherwise slow storage. Improve this by loading the options and thus checking the git config only once before the checkout. Bug: 579715 Change-Id: I21cd5a808f9d90b5ca2d022f91f0eeb8ca26091c Signed-off-by: Thomas Wolf <twolf@apache.org>
* Implement ours/theirs content conflict resolutionThomas Wolf2021-04-191-26/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | Git has different conflict resolution strategies: * There is a tree merge strategy "ours" which just ignores any changes from theirs ("-s ours"). JGit also has the mirror strategy "theirs" ignoring any changes from "ours". (This doesn't exist in C git.) Adapt StashApplyCommand and CherrypickCommand to be able to use those tree merge strategies. * For the resolve/recursive tree merge strategies, there are content conflict resolution strategies "ours" and "theirs", which resolve any conflict hunks by taking the "ours" or "theirs" hunk. In C git those correspond to "-Xours" or -Xtheirs". Implement that in MergeAlgorithm, and add API to set and pass through such a strategy for resolving content conflicts. * The "ours/theirs" content conflict resolution strategies also apply for binary files. Handle these cases in ResolveMerger. Note that the content conflict resolution strategies ("-X ours/theirs") do _not_ apply to modify/delete or delete/modify conflicts. Such conflicts are always reported as conflicts by C git. They do apply, however, if one side completely clears a file's content. Bug: 501111 Change-Id: I2c9c170c61c440a2ab9c387991e7a0c3ab960e07 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Update EDL 1.0 license headers to new short SPDX compliant formatMatthias Sohn2020-01-041-38/+5
| | | | | | | | | | This is the format given by the Eclipse legal doc generator [1]. [1] https://www.eclipse.org/projects/tools/documentation.php?id=technology.jgit Bug: 548298 Change-Id: I8d8cabc998ba1b083e3f0906a8d558d391ffb6c4 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Merge branch 'stable-5.2' into stable-5.3Matthias Sohn2019-08-081-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-5.2: Fix OpenSshConfigTest#config FileSnapshot: fix bug with timestamp thresholding In LockFile#waitForStatChange wait in units of file time resolution Cache FileStoreAttributeCache per directory Fix FileSnapshot#save(long) and FileSnapshot#save(Instant) Persist minimal racy threshold and allow manual configuration Measure minimum racy interval to auto-configure FileSnapshot Reuse FileUtils to recursively delete files created by tests Fix FileAttributeCache.toString() Add test for racy git detection in FileSnapshot Repeat RefDirectoryTest.testGetRef_DiscoversModifiedLoose 100 times Fix org.eclipse.jdt.core.prefs of org.eclipse.jgit.junit Add missing javadoc in org.eclipse.jgit.junit Enhance RepeatRule to report number of failures at the end Fix FileSnapshotTests for filesystem with high timestamp resolution Retry deleting test files in FileBasedConfigTest Measure filesystem timestamp resolution already in test setup Refactor FileSnapshotTest to use NIO APIs Measure stored timestamp resolution instead of time to touch file Handle CancellationException in FileStoreAttributeCache Fix FileSnapshot#saveNoConfig Use Instant for smudge time in DirCache and DirCacheEntry Use Instant instead of milliseconds for filesystem timestamp handling Workaround SecurityException in FS#getFsTimestampResolution Fix NPE in FS$FileStoreAttributeCache.getFsTimestampResolution FS: ignore AccessDeniedException when measuring timestamp resolution Add debug trace for FileSnapshot Use FileChannel.open to touch file and set mtime to now Persist filesystem timestamp resolution and allow manual configuration Increase bazel timeout for long running tests Bazel: Fix lint warning flagged by buildifier Update bazlets to latest version Bazel: Add missing dependencies for ArchiveCommandTest Bazel: Remove FileTreeIteratorWithTimeControl from BUILD file Add support for nanoseconds and microseconds for Config#getTimeUnit Optionally measure filesystem timestamp resolution asynchronously Delete unused FileTreeIteratorWithTimeControl FileSnapshot#equals: consider UNKNOWN_SIZE Timeout measuring file timestamp resolution after 2 seconds Fix RacyGitTests#testRacyGitDetection Change RacyGitTests to create a racy git situation in a stable way Deprecate Constants.CHARACTER_ENCODING in favor of StandardCharsets.UTF_8 Fix non-deterministic hash of archives created by ArchiveCommand Update Maven plugins ecj, plexus, error-prone Update Maven plugins and cleanup Maven warnings Make inner classes static where possible Fix API problem filters Change-Id: I238adfd3080a5fed9d64c3c757297da6ea893918 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| * Use Instant instead of milliseconds for filesystem timestamp handlingMatthias Sohn2019-07-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This enables higher file timestamp resolution on filesystems like ext4, Mac APFS (1ns) or NTFS (100ns) providing high timestamp resolution on filesystem level. Note: - on some OSes Java 8,9 truncate milliseconds, see https://bugs.openjdk.java.net/browse/JDK-8177809, fixed in Java 10 - UnixFileAttributes truncates timestamp resolution to microseconds when converting the internal representation to FileTime exposed in the API, see https://bugs.openjdk.java.net/browse/JDK-8181493 - WindowsFileAttributes also provides only microsecond resolution Change-Id: I25ffff31a3c6f725fc345d4ddc2f26da3b88f6f2 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | Return 'this' from setters in commandsMario Molina2019-01-071-6/+36
|/ | | | | | | | | To avoid breaking ABI, take the opportunity to give these setters (hopefully sometimes better) names and deprecate their old names. Change-Id: Ib45011678c3d941f8ecc1a1e0fdf4c09cdc337e3 Signed-off-by: Mario Molina <mmolimar@gmail.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
* Remove 'final' in parameter listsHan-Wen Nienhuys2018-05-151-2/+2
| | | | | Change-Id: Id924f79c8b2c720297ebc49bf9c5d4ddd6d52547 Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
* Fix javadoc in org.eclipse.jgit annotations and api packagesMatthias Sohn2017-12-181-8/+14
| | | | Change-Id: I2761ea91f8dfed16ea54e7a6646af03a30c15ec9 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* TreeWalk: Make getEolStreamType(OperationType) publicDavid Pursehouse2017-11-151-1/+4
| | | | | | | | | and deprecate getEolStreamType(). This resolves a TODO that was apparently supposed to be done in version 4.4. Change-Id: I5c9861aedabdc3f99dcf47519b3959a979e6a591
* Send a detailed event on working tree modificationsThomas Wolf2017-08-151-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently there is no way to determine the precise changes done to the working tree by a JGit command. Only the CheckoutCommand actually provides access to the lists of modified, deleted, and to-be-deleted files, but those lists may be inaccurate (since they are determined up-front before the working tree is modified) if the actual checkout then fails halfway through. Moreover, other JGit commands that modify the working tree do not offer any way to figure out which files were changed. This poses problems for EGit, which may need to refresh parts of the Eclipse workspace when JGit has done java.io file operations. Provide the foundations for better file change tracking: the working tree is modified exclusively in DirCacheCheckout. Make it emit a new type of RepositoryEvent that lists all files that were modified or deleted, even if the checkout failed halfway through. We update the 'updated' and 'removed' lists determined up-front in case of file system problems to reflect the actual state of changes made. EGit thus can register a listener for these events and then knows exactly which parts of the Eclipse workspace may need to be refreshed. Two commands manage checking out individual DirCacheEntries themselves: checkout specific paths, and applying a stash with untracked files. Make those two also emit such a new WorkingTreeModifiedEvent. Furthermore, merges may modify files, and clean, rm, and stash create may delete files. CQ: 13969 Bug: 500106 Change-Id: I7a100aee315791fa1201f43bbad61fbae60b35cb Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
* Enable and fix 'Should be tagged with @Override' warningDavid Pursehouse2017-02-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Set missingOverrideAnnotation=warning in Eclipse compiler preferences which enables the warning: The method <method> of type <type> should be tagged with @Override since it actually overrides a superclass method Justification for this warning is described in: http://stackoverflow.com/a/94411/381622 Enabling this causes in excess of 1000 warnings across the entire code-base. They are very easy to fix automatically with Eclipse's "Quick Fix" tool. Fix all of them except 2 which cause compilation failure when the project is built with mvn; add TODO comments on those for further investigation. Change-Id: I5772061041fd361fe93137fd8b0ad356e748a29c Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Fix StashApplyCommand for stashes containing untracked changes.Thomas Wolf2017-01-151-5/+5
| | | | | | | | | | | If there are untracked changes, apply only the untracked tree after a successful merge. The merge tree from merging untracked with HEAD would also contain files already reset before (changes in tracked files) and try to reset those again,leading to false checkout conflicts. Bug: 505804 Change-Id: Iaced4d277623334d11e3d1cca5969590d7c5093e Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
* Fix StashApply regarding handling of untracked filesChristian Halstrick2016-05-191-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There was a bug regarding how JGit handled untracked files when applying a stash. Problem was that untracked files are applied by doing a merge of HEAD and untrackedFiles commit with a merge base of the stashed HEAD. That's wrong because the untrackedFiles commit has no parent and contains only the untracked files. Using stashed HEAD as merge base leads to unneccessary conflicts on files not event included in the untrackedFiles commit. Imagine this graph directly before you want to apply a stash which was based on 0. You want to apply the stash on current HEAD commit 5. 5 (HEAD,master) / 0---+ \ \ 1---3 (WIP on master) / 2 (untracked files on master) Imagine for a specific (tracked) file f - commit 0 contains X - HEAD contains Y - commit 2 (the untracked files) does not contain file f A merge of 2 and 5 with a merge base of 0 leads to a conflict. The 5 commit wants to modify the file and the 2 commit wants to delete the file -> conflict. If no merge base is set then the semantic is correct. Thanks to Bow for finding this bug and providing the test case. Bug: 485467 Change-Id: I453fa6ec337f81b2a52c4f51f23044faeec409e6 Also-by: Bow Ruggeri <bow@bow.net> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Add EOL stream type detection to TreeWalkIvan Motsch2016-03-071-3/+9
| | | | | | | | | | | | | | TreeWalk provides the new method getEolStreamType. This new method can be used with EolStreamTypeUtil in order to create a wrapped InputStream or OutputStream when reading / writing files. The implementation implements support for the git configuration options core.crlf, core.eol and the .gitattributes "text", "eol" and "binary" CQ: 10896 Bug: 486563 Change-Id: Ie4f6367afc2a6aec1de56faf95120fff0339a358 Signed-off-by: Ivan Motsch <ivan.motsch@bsiag.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Delete non empty directories before checkout a pathAndrey Loskutov2015-10-091-1/+1
| | | | | | | | | | If the checkout path is currently a non-empty directory (and was a link or a regular file before), this directory will be removed before performing checkout, but only if the checkout path is specified. Bug: 474973 Change-Id: Ifc6c61592d9b54d26c66367163acdebea369145c Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
* Silence non-externalized string warnings in org.eclipse.jgitMatthias Sohn2015-05-261-4/+4
| | | | Change-Id: I7fa180db0c59e4a317a0c99ec48574cb0e5ac2f2 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Use AutoClosable to close resources in bundle org.eclipse.jgitMatthias Sohn2015-05-211-14/+5
| | | | | | | - use try-with-resource where possible - replace use of deprecated release() by close() Change-Id: I0f139c3535679087b7fa09649166bca514750b81 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Deprecate checkoutEntry variant that accepts FileShawn Pearce2014-11-271-3/+1
| | | | | | | | Entries should only be written to the working tree managed by the Repository. Simplify callers by passing only the entry and computing the work tree location inside of the checkoutEntry method. Change-Id: I574e41280d0407f1853fda12f4bd0d30f75d74e7
* Cleanup TreeWalk creation/release inside StashApplyCommandShawn Pearce2014-11-241-4/+2
| | | | | | | | | | The TreeWalk constructor doesn't throw in a meaninful way that requires cleanup of the not-yet-created TreeWalk. Hoist the constructor outside of the try/finally and remove the now unnecessary != null check during the finally. Change-Id: If5b8bb91562715df0699726648123a47426b9850
* Rename local variables/parameters to remove warnings about hidingRobin Rosenberg2014-09-041-3/+3
| | | | Change-Id: I73f38492b6a2e7fd6e77005efd0a8a8c65763e74
* Allow to include untracked files in stash operations.Andreas Hermann2014-05-221-3/+95
| | | | | | | | | | | Unstashed changes are saved in a commit which is added as an additional parent to the stash commit. This behaviour is fully compatible with C Git stashing of untracked files. Bug: 434411 Change-Id: I2af784deb0c2320bb57bc4fd472a8daad8674e7d Signed-off-by: Andreas Hermann <a.v.hermann@gmail.com>
* Allow callers to use different merging strategiesLaurent Goubet2014-05-061-3/+16
| | | | | Signed-off-by: Laurent Goubet <laurent.goubet@obeo.fr> Change-Id: I84e9d7b4b772b4ad7d3e7010aad78291d4d178fe
* Implement rebase.autostashStefan Lay2013-12-041-1/+14
| | | | | | | This feature was introduced in native git with version 1.8.4. Bug: 422951 Change-Id: I42f194174d64d7ada6631e2156c2a7bf93b5e91c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Fix applying stash on other commitStefan Lay2013-11-291-0/+1
| | | | | | | | Applying a stash on another commit failed because the merge base for the cherry-pick of the stashed index state was not corectly set. Bug: 422684 Change-Id: I9355352b2b9a7abefa3248ca3c17a9301177d0d6 Signed-off-by: Stefan Lay <stefan.lay@sap.com>
* Add NON-NLS comments for some obviously untranslatable stringsRobin Rosenberg2013-07-211-1/+1
| | | | | Change-Id: I2d1076b46695dac84961b8ae663bfc5cb123b3a3 Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
* Make recursive merge strategy the default merge strategyMatthias Sohn2013-04-151-2/+2
| | | | | | | | Use recursive merge as the default strategy since it can successfully merge more cases than the resolve strategy can. This is also the default in native Git. Change-Id: I38fd522edb2791f15d83e99038185edb09fed8e1 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Fix stash apply using merge logicRobin Rosenberg2013-01-301-226/+107
| | | | | | | | | | | | Instead of the complicated strange stuff, implement staah apply as cherry-pick. Provided there are no conflicts and it is requested that the index should be applied, perform yet another cherry-pick, but discard tha results thereof it that would result in conflicts. Bug: 376035 Change-Id: I553f3a753e0124b102a51f8edbb53ddeff2912e2
* Mark non-externalizable strings as suchRobin Rosenberg2012-12-271-3/+3
| | | | | | | | | | A few classes such as Constanrs are marked with @SuppressWarnings, as are toString() methods with many liternal, but otherwise $NLS-n$ is used for string containing text that should not be translated. A few literals may fall into the gray zone, but mostly I've tried to only tag the obvious ones. Change-Id: I22e50a77e2bf9e0b842a66bdf674e8fa1692f590
* Further cleanup of exceptions in Git APIRobin Rosenberg2012-06-051-1/+4
| | | | | | | | | - Translate internal exceptions to corresponding API exception - Do not catch GitAPI exceptions internally to an internal exception. Just pass them to caller - Mention thrown exceptions in javadoc Change-Id: I9044cf86d2b0bcc8b63b7cc016e1bf0055a62053 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Git API does not declare GitAPIException call() and related cleanupsRobin Rosenberg2012-05-301-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | All commands should throw a GitAPIException so new exceptions can be added without breaking the builds of old code, i.e. anyone that calls a Git API should catch GitAPIException and not just the currently known exceptions. Now the only checked exceptions on Git API calls are GitException and subclasses of it. New checked exceptions that are subclasses of GitException may be added without breaking the API. Javadoc for GitAPIException is declared on GitCommand and inherited to subclasses. JGitInternalException is not explicitly documented anymore. Unfortunately this change itself breaks the API. The intention is that it shall be possible to add new checked subclasses of GitAPIException without breaking the API. Bug: 366914 EGit-Change-Id: I50380f13fc82c22d0036f47c7859cc3a77e767c5 Change-Id: I50380f13fc82c22d0036f47c7859cc3a77e767c5 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Only unstash files changed when originally stashedKevin Sawicki2012-03-131-49/+232
| | | | | | | | | | | | | | | | | | | Previously a DirCacheCheckout was done using a merge tree reflecting the state of the repository when the stash was originally done. This was wrong since unstashing after making subsequent commits would undo changes already committed by checking out entries from an outdated tree. The new approach is to scan for conflicts initially using a 6-way tree walk that contains the trees for the stashed HEAD, stashed index, stashed working directory, current HEAD, current index, and current working directory. Then perform a subsequent scan of the stashed HEAD, index, and working directory trees and apply all the stashed differences to the current index and working directory. Bug: 372882 Change-Id: Ica65f162132c00a16964e838de66fc8b5cd0b0aa Signed-off-by: Chris Aniszczyk <zx@twitter.com>
* Move JGitText to an internal packageRobin Rosenberg2012-03-121-1/+1
| | | | Change-Id: I763590a45d75f00a09097ab6f89581a3bbd3c797
* Add command support for applying a stashed commitKevin Sawicki2012-02-281-0/+195
Applies the changes in a stashed commit to the local working directory and index Bug: 309355 Change-Id: I9fd5ede8affc7f0060ffa7c5cec34573b6fa2b1b Signed-off-by: Chris Aniszczyk <zx@twitter.com>