Commit Graph

156 Commits

Author SHA1 Message Date
David Pursehouse 0b4e781f7c Use StandardCharsets.UTF_8 in tests
Replace hard-coded "UTF-8" string with the constant.

Change-Id: Ie812add2df28e984090563ec7c6e2c0366616424
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-07 09:04:36 +09:00
David Pursehouse 594722530b ArchiveTest: Open auto-closeable resources in try-with-resource
Change-Id: If11017f21027b46c7a66e52e4bc0cc73f4fbdc07
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 20:23:03 +09:00
Matthias Sohn 2464fa440f Fix remaining javadoc errors raised by doclint
For now ignore doclint "missing" warnings.

Change-Id: I0e5af7a757f4d92ffeeb113f30576a35414d6781
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-21 02:42:14 +01:00
David Pursehouse 0ea73f6282 ArchiveTest: Check result of BufferedInputStream#skip
Change-Id: I5168c75ca2dda6d1e8c8a6c29043ac781fe9295a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-07 20:02:59 +09:00
Ned Twigg f333c7496b Checkout now reports failures through exceptions.
Checkout sometimes throws an exception, and
other times it writes an error message to outw
and returns normally, even though the command
failed.  This commit now reports all failures
through a die() exception.

Change-Id: I038a5d976d95020fea3faac68e9178f923c25b28
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
2017-10-01 00:07:26 -04:00
Ned Twigg c1fbef3cab Added API to TextBuiltin for piped usage.
Added a public method to TextBuiltin which makes it possible for
clients to initialize all of its state, including output and error
streams.  This gives clients the ability to customize the way in
which a command is run.

Change-Id: If718236964d2c5cf869e120c74f1a12965f4812e
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
2017-09-21 14:48:45 -04:00
Matthias Sohn 3af57b52a3 Update args4j to 2.33
CQ: 11068
Change-Id: I7d52cddacff05477f646fda5f7b9f2de844922f6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-08-30 03:07:35 +02:00
Robin Stocker c02c9e8042 Fix compilation errors with args4j 2.0.23 and later
The multiValued attribute on @Option was removed. When the field is a
List, it's not actually needed (even with earlier versions of args4j),
see RmTest. In other cases, we have a custom handler, where it's also
not needed.

Bug: 413163
Change-Id: I4bb951e9fab5f4ae4271bd7e11be799dc234ab80
2017-08-30 03:07:35 +02:00
David Pursehouse 4940ea14b7 Add missing newlines at ends of Java files
Change-Id: Iead36f53d57ead0eb3edd3f9efb63b6630c9c20c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-07-25 10:37:21 +01:00
Oliver Lockwood 43672700e7 Add --match option for `jgit describe` to CLI
This adds --match option for glob(7) matchers on git tags to jgit
describe in CLI.

Bug: 518377
Change-Id: I745988d565dd4391e8b3e5a91bbfbae575333819
Signed-off-by: Oliver Lockwood <oliver.lockwood@cantab.net>
2017-06-22 09:08:55 +02:00
Yasuhiro Takagi a66e60a986 ArchiveCommand: Create prefix entry with commit time
The cgit archive command creates a prefix (root) directory entry
in the archive file. That entry's time is set to the commit time.

This patch makes jgit's behavior consistent with with cgit:

prefix: hoge/     -> creates prefix directory "hoge/" entry.
prefix: hoge////  -> creates prefix directory "hoge/" entry.
prefix: hoge/foo  -> does not create prefix directory entry, but for
                     each file/directory entry, prefix is added.

Change-Id: I2610e40ce37972c5f7456fdca6337e7fb07176e5
Signed-off-by: Yasuhiro Takagi <ytakagi@bea.hi-ho.ne.jp>
2017-06-05 19:35:46 -04:00
David Turner 6b1e3c58b1 Run auto GC in the background
When running an automatic GC on a FileRepository, when the caller
passes a NullProgressMonitor, run the GC in a background thread. Use a
thread pool of size 1 to limit the number of background threads spawned
for background gc in the same application. In the next minor release we
can make the thread pool configurable.

In some cases, the auto GC limit is lower than the true number of
unreachable loose objects, so auto GC will run after every (e.g) fetch
operation.  This leads to the appearance of poor fetch performance.
Since these GCs will never make progress (until either the objects
become referenced, or the two week timeout expires), blocking on them
simply reduces throughput.

In the event that an auto GC would make progress, it's still OK if it
runs in the background. The progress will still happen.

This matches the behavior of regular git.

Git (and now jgit) uses the lock file for gc.log to prevent simultaneous
runs of background gc. Further, it writes errors to gc.log, and won't
run background gc if that file is present and recent. If gc.log is too
old (according to the config gc.logexpiry), it will be ignored.

Change-Id: I3870cadb4a0a6763feff252e6eaef99f4aa8d0df
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-06-06 01:18:29 +02:00
David Pursehouse 3b4448637f Enable and fix warnings about redundant specification of type arguments
Since the introduction of generic type parameter inference in Java 7,
it's not necessary to explicitly specify the type of generic parameters.

Enable the warning in Eclipse, and fix all occurrences.

Change-Id: I9158caf1beca5e4980b6240ac401f3868520aad0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-02-20 22:47:23 +01:00
David Pursehouse 7ac182f4e4 Enable and fix 'Should be tagged with @Override' warning
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>
2017-02-19 20:05:08 -04:00
David Pursehouse a45cfee7a3 Organize imports
Change-Id: I7c545d06b1bced678c020fab9af1382bc4416b6e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-11-14 13:25:20 -08:00
Rüdiger Herrmann a5eccf4a4d Preserve backslashes within double quotes in CLIGitCommand::split()
Change-Id: Ia6a56512baa6a0f27e2eef1b19ebb60291ba377f
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
2016-10-23 15:29:17 +09:00
Ned Twigg e49025386e Checkout: Add the ability to checkout all paths.
Change-Id: Ie1e59c566b63d0dfac231e44e7ebd7f3f08f3e9f
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-10-22 10:08:07 +09:00
David Pursehouse 8f9e157cd5 ArchiveTest: Don't use string concatenation in loop
According to FindBugs:

  In each iteration, the String is converted to a StringBuffer/
  StringBuilder, appended to, and converted back to a String. This
  can lead to a cost quadratic in the number of iterations, as the
  growing string is recopied in each iteration.

Replace string concatenation with StringBuffer.

Change-Id: I60e09f274bed6722f4e0e4d096b0f2b1b31ec1b4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-10-19 15:09:31 +09:00
Christian Halstrick 293e8beacc Fix JGit CLI to follow native git's interpretation of http_proxy...
Native git (as many other tools) interprets the environment variables
http_proxy, HTTP_PROXY, ... in a specific way. "http_proxy" has to be
lowercase while "https_proxy" can be lowercase or uppercase (means:
"HTTPS_PROXY"). Lowercase has precedence. This can be looked up in
"ENVIRONMENT" section of [1]. Teach JGit CLI to behave similar.

Additionally teach JGit not to interpret the environment variables if
the java process was explicitly started with the system properties
telling JVM which proxy to use. A call like "http_proxy=proxy1 java
-Dhttp.proxyHost=proxy2 ..." should use proxy2 as proxy.

[1] https://curl.haxx.se/docs/manpage.html

Change-Id: I2ad78f209792bf8f1285cf2f8ada8ae0c28f8e5a
2016-10-14 15:14:21 +02:00
Ned Twigg b67df51203 CLI: implement option -d for deleting tags
Change-Id: I438456b76aefd361384729686271288186d3be3b
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-08-31 00:16:23 +02:00
Ned Twigg 34673f0536 Added a clean command.
Change-Id: I05d5392789b5b64e6ee44f678556cf25dc30d7ba
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
2016-08-30 22:21:05 +02:00
Christian Halstrick 5fe44ed3ee Fix DirCacheCheckout to return CheckoutConflictException
Problem occurs when the checkout wants to create a file 'd/f' but
the workingtree contains a dirty file 'd'. In order to create d/f the
file 'd' would have to be deleted and since the file is dirty that
content would be lost. This should lead to a CheckoutConflictException
for d/f when failOnConflict was set to true.

This fix also changes jgit checkout semantics to be more like native
gits checkout semantics. If during a checkout jgit wants to delete a
folder but finds that the working tree contains a dirty file at this
path then JGit will now throw an exception instead of silently keeping
the dirty file. Like in this example:

	git init
	touch b
	git add b
	git commit -m addB
	mkdir a
	touch a/c
	git add a/c
	git commit -m addAC
	rm -fr a
	touch a
	git checkout HEAD~

Change-Id: I9089123179e09dd565285d50b0caa308d290cccd
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
Also-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
2016-06-23 09:34:22 +02:00
Hugo Arès f0a485d5a2 Add missing @Test annotations
Change-Id: Ie5ffcbf18233dc9b3eb232f714b5b58b6b93f4e0
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
2016-06-01 16:06:23 -04:00
Rüdiger Herrmann 8ff08994a4 JGit CLI: allow to call git init with specific directory
With this change it is possible to initialize repositories with
'git init /path/to/new/repo'

Change-Id: Ia9b288b4fb34887e8f5e2f3f270e521c44d41b6a
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-05-22 22:11:03 +02:00
David Pursehouse 77887b49f9 ReflogTest: Open Git instances in try-with-resource
Change-Id: I950b6f16148cfe11de729b04904f88d6e4c28b9a
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-12 12:26:58 +09:00
David Pursehouse ef471b0861 RepoTest: Open Git in try-with-resources
Allocate a new Git for each part of the test, rather than
reassigning to the same variable.

Change-Id: Ic83778bbff0b2f57d37b95aef70324859d42cd58
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-05 18:17:02 +09:00
Matthias Sohn 4ec84fac86 Merge branch 'master' into stable-4.2
Change-Id: Ieec4f51aedadf5734ae0e3f4e8713248a3c4fc52
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-21 17:07:31 +01:00
David Pursehouse 72c94465bc ConfigTest: Create Git instance in try-with-resource
Change-Id: Ie65c69e0f1aed95bcdf68ebd68d21b3e2590b41c
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-21 15:31:56 +09:00
David Pursehouse aca07fac46 Merge branch 'stable-4.2'
* stable-4.2:
  CheckoutCommandTest: Create Git instances in try-with-resource
  BranchCommandTest: Create Git instances in try-with-resource
  CheckoutTest: Create Git instances in try-with-resource
  BranchTest: Create Git instances in try-with-resource
  URIishTest: Use @Test annotation's `expected` argument
  Suppress "The allocated object is never used" warning in tests
  Add $NON-NLS to suppress "Non-externalized string literal" warnings
  Don't use deprecated constructors of CmdLineException
  Prepare 4.2.0-SNAPSHOT builds
  Remove org.eclipse.jgit.updatesite project from tools/version.sh
  RevParse: Remove superfluous semicolon
  RefUpdateTest: Use try-with-resource for auto-closable types
  RefUpdateTest: Add null check to prevent potential NPE
  CommitCommand: Remove redundant null check
  JGit v4.2.0.201512141825-rc1

Change-Id: I2179859289b2f2e3d0b7c6d02ef7e7890c467f7b
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-20 09:45:48 +09:00
David Pursehouse 7f84e40f31 CheckoutTest: Create Git instances in try-with-resource
Change-Id: I49a03f7bee0b61c062ce160674f9aa0cd1bcc8ba
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-19 17:27:46 +01:00
David Pursehouse 9d721de69b BranchTest: Create Git instances in try-with-resource
Change-Id: I8becee479fab91a18e6daffd6f4fd57338c9d120
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-19 17:27:46 +01:00
Andrey Loskutov 7780a4ee31 Make sure CLIGitCommand and Main produce (almost) same results
Currently execution of tests in pgm uses CLIGitCommand which
re-implements few things from Main. Unfortunately this can results in a
different test behavior compared to the real CLI runtime.

The change let CLIGitCommand extend Main and only slightly modifies the
runtime (stream redirection and undesired exit() termination).

Change-Id: I87b7b61d1c84a89e5917610d84409f01be90b70b
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-06 17:27:31 -05:00
Andrey Loskutov fb5056c2c5 branch command: print help if requested, even if arguments are wrong
git branch -d -h reports an error (because of missing -d option value)
but does not print the help as expected.

To fix this, CmdLineParser must catch, print but do not propagate
exceptions if help is requested.

Bug: 484951
Change-Id: I51265ebe295f22da540792c6a1980b8bdb295a02
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-06 17:27:15 -05:00
Andrey Loskutov 24468f09e3 Added CLIText.fatalError(String) API for tests
In different places (Main, TextBuiltin, CLIGitCommand) we report fatal
errors and at same time want to check for fatal errors in the tests.
Using common API simplifies the error testing and helps to navigate to
the actual error check implementation.

Change-Id: Iecde79beb33ea595171f168f46b0b10ab2f339bb
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-06 17:26:43 -05:00
Andrey Loskutov 63bb0bcd4a branch command: provide convenient and meaningful options help
Added tests for all options, fixed multi-valued options parsing.

Bug: 484951
Change-Id: I5558589049544ea6c84932bc01f1f9df09e1f682
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-02 17:41:59 +01:00
Andrey Loskutov d6deb190e6 Simplify pgm tests: allow varargs and trim output for toString()
Change-Id: Ia5bcd9e560b90cf872fef75c2800c889ef1cc85a
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-02 17:41:58 +01:00
Andrey Loskutov 35db319e8a Fixed few locale dependent pgm tests
See https://dev.eclipse.org/mhonarc/lists/jgit-dev/msg03040.html

Change-Id: If51f3c750684d82cb6443f1578636c9f5ca56e2b
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-02 17:41:58 +01:00
Andrey Loskutov 02ade82b34 Make sure tests don't blindly continue if a command is "silently" failed
Make the default execute() function fail fast on first command printed
"fatal: " to output.

Introduced executeUnchecked() for few tests which wanted to test fatal
output.

Change-Id: I5b09aad9443515636811fc4d00bf8b8b9587a626
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-31 00:48:11 +01:00
Andrey Loskutov aabbc58341 Sort "eager" path-like options to the end of the help
The "--" path option (and all other similar options consuming all
remaining arguments) should be placed at the end of the command line
help.

Currently jgit reset -h shows this:

jgit reset [commit-ish] [path ... ...] [-- path ... ...] [--hard]
[--help (-h)] [--mixed] [--soft]

After the patch the help shows this:

jgit reset [commit-ish] [path ... ...] [--hard] [--help (-h)] [--mixed]
[--soft] [-- path ... ...]

Bug: 484951
Change-Id: I3db332bf293ca8d6bfaab0d546cd35af689bd46e
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 15:00:31 +01:00
Andrey Loskutov 97b4c02cda reset command: provide convenient and meaningful options help
This commit changes the jgit "reset" command line options help from
this:

jgit reset name [VAL ...] [-- path ... ...] [--hard] [--help (-h)]
[--mixed] [--soft]
 name        : Reset current HEAD to the specified state
 [...]

to this:

jgit reset [commit-ish] [path ... ...] [-- path ... ...] [--hard]
[--help (-h)] [--mixed] [--soft]
 commit-ish  : Reset to given reference name
 [...]

Bug: 484951
Change-Id: I614e71101b4f9f46ef8f02379d1a9d135f3292d2
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 15:00:17 +01:00
Andrey Loskutov 0505657d6a commit command: allow to specify path(s) argument(s)
This fixes the command below:

jgit commit a -m "added file a"

which currently fails with:

org.eclipse.jgit.api.errors.JGitInternalException: The combination of
arguments --all and --only is not allowed

Bug: 484973
Change-Id: I37a4ccd68101a66520ef99110f7aa0cbdcc8beba
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 15:00:09 +01:00
Andrey Loskutov c1b31b3f3b repo command: properly name the required 'path' argument
Fixes point 4 in bug 484951, where "jgit repo" or "jgit repo -h" dumps a
stack trace.

Bug: 484951
Change-Id: Ic8b362e07a40ad923dc9acde0c0983a1e7932a02
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 14:35:08 +01:00
Andrey Loskutov 888f08b048 Un-ignored existing CLI tests which run just fine on Java 7+
Change-Id: I5ef334a49fb2d88d5e856b443687f3dcb126a77a
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 14:35:08 +01:00
Andrey Loskutov c59d86c0a7 Don't treat command termination due '-h' option as a fatal error
Signal early command termination due '-h' or '--help' option via
TerminatedByHelpException. This allows tests using
CLIGitCommand differentiate between unexpected command parsing errors
and expected command cancellation "on help" (which also allows
validation of expected/unexpected help messages).

Additional side-effect: jgit supports now git style of handling help
option: any unexpected command line options before help are reported as
errors, but after help ignored.

Bug: 484951
Change-Id: If45c41c0d32895ab6822a7ff9d851877dcef5771
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 14:35:08 +01:00
Andrey Loskutov c7c2897527 Allow checkout paths without specifying branch name
JGit CLI should allow to do this: checkout -- <path>

Currently, even if "a" is a valid path in the git repo, jgit CLI can't
checkout it:
$jgit checkout -- a
error: pathspec 'a' did not match any file(s) known to git.

The fix also fixes at same time "unnamed" zombie "[VAL ...]" argument
shown on the command line.

Before fix:
$jgit -h
jgit checkout name [VAL ...] [-- path ... ...] [--force (-f)] [--help
(-h)] [--orphan] [-b]

After fix:
$jgit -h
jgit checkout [name] [-- path ... ...] [--force (-f)] [--help (-h)]
[--orphan] [-b]

Bug: 475765
Change-Id: I2b0e77959a72e4aac68452dc3846adaa745b0831
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-28 10:56:21 +01:00
Kaloyan Raev e23521f0d9 Add remote command to JGit CLI
Supported subcommands are:
 - <none> (lists available remotes)
 - add
 - remove
 - set-url
 - update
 
Supported options are:
 --verbose
 --push
 --prune

Bug: 481316
Change-Id: I57c34ed6daabb7d308bc383b17c1ef4af433e714
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-11 22:54:48 +01:00
Jonathan Nieder 5be4814e38 Repository: Introduce exactRef and findRef, deprecate getRef
The Repository class provides only one method to look up a ref by
name, getRef.  If I request refs/heads/master and that ref does not
exist, getRef will look further in the search path:

 ref/refs/heads/master
 refs/heads/refs/heads/master
 refs/remotes/refs/heads/master

This behavior is counterintuitive, needlessly inexpensive, and usually
not what the caller expects.

Allow callers to specify whether to use the search path by providing
two separate methods:

- exactRef, which looks up a ref when its exact name is known
- findRef, which looks for a ref along the search path

For backward compatibility, keep getRef as a deprecated synonym for
findRef.

This change introduces findRef and exactRef but does not update
callers outside tests to use them yet.

Change-Id: I35375d942baeb3ded15520388f8ebb9c0cc86f8c
Signed-off-by: Jonathan Nieder <jrn@google.com>
2015-11-25 14:05:20 -08:00
Kaloyan Raev 96811c957e reset command should support the -- <paths> parameters
Bug: 480750
Change-Id: Ia85b1aead03dcf2fcb50ce0391b656f7c60a08d4
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
2015-10-29 11:58:08 +02:00
Hugo Arès 61e1645e04 Fix integer boxing eclipse warning
There was this warning because private assertEquals(Object, Object)
method was shadowing JUnit assertEquals methods.

Change-Id: I889bfe1d8c48210d9a42147a523c4829c5b5d1e3
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
2015-09-16 13:15:21 -04:00
Jonathan Nieder a5778b6f41 archive: Drop unnecessary empty comments and 'final' qualifiers on locals
Early JGit code used comments to inform the Eclipse formatter about
where to break lines and used final in the hope of making code faster.
The ArchiveCommand command implementation imitated that style.

Nowadays the project relies less on the Eclipse formatter and relies
more on Java having sane performance with local variables that are not
explicitly marked 'final'.  Removing the unnecessary empty comments and
'final' qualifiers makes this code more readable and more consistent
with recent JGit code.

Change-Id: I7a181432eda7e18bd32cf110d89c0efbe490c4f1
Signed-off-by: Jonathan Nieder <jrn@google.com>
2015-05-27 16:49:34 -07:00
Kaloyan Raev 9041fbc958 CLI status should support --untracked-files
A special options handler is added to properly handle the short -u alias
of the option.

The "normal" mode is not supported by this patch, because this mode of
listing untracked files is not
supported by the org.eclipse.jgit.lib.IndexDiff class. This mode is not
necessary for my use case. It can be added later if anyone really needs
it.

The StatusTest is updated to cover all possible combinations of the
--porcelain and --untracked-files options.

Bug: 459319
Change-Id: I305ac95739cfed0c16735e0987844e57fa27e236
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-03-12 18:10:26 -07:00
Christian Halstrick 0e3ddea1b0 Add "--long" option to JGit describe
Native git supports "git describe --long". This will enforce returning a
long description of a commit even if a tag is directly pointing to the
commit (in contrast to just returning the tag name as it is now). This
commit teaches JGits DescribeCommand and the describe command in the pgm
package to support "--long".

Bug: 460991
Change-Id: I65e179b79e89049c6deced3c71cb3ebb08ed0a8f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-03-09 13:48:04 -07:00
Rüdiger Herrmann fc801dd79f Add option --orphan for checkout
Change-Id: I546a93f3e147d8d6fc70094b22679c0d11cd8921
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
2015-02-04 13:35:32 +01:00
Matthias Sohn 15e8b4fb2e [pgm] Add option --bare to clone command
Change-Id: I528491e3e20d3c9ebe37fe3cd2bf85b4644d8698
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-12-22 15:45:46 +01:00
Matthias Sohn 563c1ad514 [pgm] Implement clone using CloneCommand
Change-Id: I56699b7bf9a71f673cb308d3015f51de5b06c1d9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-12-22 15:43:44 +01:00
Matthias Sohn 8812e6f3f6 [pgm] Add option --tags for ls-remote
Bug: 444072
Change-Id: I52b470924609fc201e078d9d232aad257506728d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-12-16 15:29:08 +01:00
Matthias Sohn 490660a7c6 [pgm] Add option --heads for ls-remote
TODO: find a way to use option -h which is already captured by
TextBuiltin's option --help which also uses the alias -h.

Bug: 444072
Change-Id: Ie66584c2fc7fc224014a43cf928547703dd9d213
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-12-16 15:28:16 +01:00
Matthias Sohn 816de9e9fa [pgm] Use LsRemoteCommand to implement ls-remote and add a test
Change-Id: Ic266f844c23e2519df5770ca56284b26e4cfe1f4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-12-15 15:59:38 +01:00
Axel Richard 46f3007b52 Handle -m option for Merge command
Set the commit message to be used for the merge commit (in case one is
created)

Bug: 442886
Change-Id: Ie5ecc13822faa366f00b3daa07f74c8441cae195
Signed-off-by: Axel Richard <axel.richard@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-08-30 01:17:24 +02:00
Yuxuan 'fishy' Wang 73d38bfb33 Strip trailing /s in repo base URI.
Change-Id: I71040db2cca69638cfad89acdc9179ee80592b27
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
2014-07-28 16:13:50 -07:00
Robin Rosenberg fd58cbcdee Don't prefix output from jgit status with '# '
C Git does not do it anymore

Bug: 439937
Change-Id: I20bdb787a00bba3e4adf269fd64ec6296bdc2a66
2014-07-19 07:31:45 -04:00
Robin Rosenberg 1a9f122773 Fix a number of failing conflict situations
Adds further tests where the working tree is dirty (differs from
index) and where we have staged but uncommitted changes.

Fixed the test case 9 for file/directory conflicts.

Bug: 428819
Change-Id: Ie44a288b052abe936ebb74272d0fefef3b218a7a
Signed-off-by: Axel Richard <axel.richard@obeo.fr>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2014-05-17 19:06:07 +02:00
Robin Rosenberg 19ac1f75ab Fix failing ConfigTest on Windows
Trust the detection of features and just test CoreConfig.

Change-Id: I37f838d270a221a75d0d3842ba2f3f90aa1d6f01
2014-05-17 04:09:22 -04:00
Matthias Sohn bbf28b1cf4 Command line: implement checkout -- <path>
Change-Id: I3d261e6541fe0fcaa210587d2aa226e153071351
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-05-12 17:12:48 -04:00
Robin Rosenberg cd1f3ecb92 cleanup: remove some unused imports
Change-Id: I549b934b86753acc362364c8986bfe6457affd12
2014-04-25 19:00:01 -04:00
Yuxuan 'fishy' Wang a44a687fed Added groups support to repo subcommand.
Change-Id: Id0e7663b6ac4f6938fdcacaf2158107b6285fc25
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
2014-04-23 23:03:00 -07:00
Yuxuan 'fishy' Wang 1f3b75c9ee Added the command line of jgit repo.
Change-Id: Ib809b00c236a9c44422a872ae801b060f5b26808
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
2014-04-23 22:59:49 -07:00
Robin Stocker 31fec678d8 Implement "git branch --contains" in pgm
Bug: 425678
Change-Id: Ib59e05a0bde58562cc61e6e3000df761660b468e
Signed-off-by: Robin Stocker <robin@nibor.org>
2014-03-07 18:24:42 -05:00
Christian Halstrick 73c8e70797 Don't raise checkout conflict for file missing in working tree
During a checkout we want to prevent to overwrite unsaved local file
content. Jgit was therefore checking whether the file to overwrite is
dirty or missing and would raise a conflict if this was the case. That
was wrong. It should only check if the file is dirty. It's ok to
"overwrite" a missing/non-existing file.

Change-Id: I63c3a94f663c87f09170fdf8b1b1bf4ed5246fc5
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2014-02-26 15:35:05 +01:00
Robin Rosenberg 078a9f6066 Add symlink support to JGit
The change includes comparing symbolic links between disk and index,
adding symbolic links to the index, creating/modifying links on
checkout. The behavior is controlled by the core.symlinks setting, just
as C Git does. When a new repository is created core.symlinks will be
set depending on the capabilities of the operating system and Java
runtime.

If core.symlinks is set to true, the assumption is that symlinks are
supported, which may result in runtime errors if this turns out not to
be the case.

Measuring the cost of jgit status on a repository with ~70000 files,
of which ~30000 are tracked reveals a penalty of about 10% for using
the Java7 (really NIO2) support module.

Bug: 354367
Change-Id: I12f0fdd9d26212324a586896ef7eb1f6ff89c39c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-02-10 22:53:33 +01:00
Matthias Sohn 74e3fde959 Remove unused import from ArchiveTest
This unnecessary import was introduced by 2ecc27d.

Change-Id: I5cb415de7e33428d9f95dfbe1e214ef24be9dad9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2014-01-07 09:22:11 +01:00
Jonathan Nieder 8a4cf2e0f8 archive: Use an empty directory for submodules
When encountering a submodule entry, "jgit archive" tries to write its
content verbatim as an entry to the archive, which fails with a
JGitInternalException wrapping a MissingObjectException because the
submodule repository commits are typically not part of the
superproject.

When a subproject is available (for example because it has been
checked out as a subdirectory of a superproject worktree), it would be
nice to recurse into it and make one archive recording the state of
the entire project.  Unfortunately sometimes the subproject is not
available or it can be hard to find (e.g., it can be on another
server).  Even when some subprojects are available, "jgit archive"
should not produce different output for the same tree depending on
which subprojects it has easy access to, so there is no obvious good
default behavior that recurses without relying on access to all
subprojects.

Instead, replace each submodule entry with a placeholder empty
directory.  "git archive" does the same.

Change-Id: I1295086037b77fc948b3f93c21d47341e25483e5
Signed-off-by: Jonathan Nieder <jrn@google.com>
2013-12-27 09:02:53 -08:00
Jonathan Nieder 2ecc27db92 archive: Include entries for directories
Entries for directories are optional and mostly wasted space in most
archive formats (except as a place to hang ownership and filesystem
permissions), but "git archive" includes them.  Follow suit.

This will make it easier in a later change to include empty
directories as placeholders for missing submodules.

Change-Id: I1810c686bcc9eb4d73498e4d3e763e18787b088a
Signed-off-by: Jonathan Nieder <jrn@google.com>
2013-12-27 08:55:39 -08:00
Jonathan Nieder f2abbd0ea9 archive: Prepend a specified prefix to all entry filenames
Common practice when distributing tarballs is to prefix all entries
with a single directory name so when the tarball is extracted it all
falls neatly into a single directory.  Add a setPrefix() method to
ArchiveCommand to support this.

Change-Id: I16b2832ef98c30977f6b77b646728b83d93c196f
Signed-off-by: Jonathan Nieder <jrn@google.com>
2013-12-17 11:22:46 -08:00
Kaloyan Raev 7026658ac8 CLI status should support --porcelain
Add support for the machine-readable output format along with the
existing default long format.

Bug: 419968
Change-Id: I37fe5121b4c9dbae1106b1d18e9fdc134070a9dd
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
2013-12-04 11:13:27 +01:00
Axel Richard 1128326add Add pgm test for checkout of existing branch with checkout conflict
Add a test that checks out an existing branch with a dirty working tree
and involves a checkout conflict. This test should pass with a message:
"error: Your local changes to the following files would be overwritten
by checkout: a".

Change-Id: I5428a04a7630d9e0101404ea1aedd796f127bd7d
Signed-off-by: Axel Richard <axel.richard@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2013-12-02 22:55:55 +01:00
Kaloyan Raev 40e8ba4186 CLI fetch command should support --tags
Bug: 419638
Change-Id: I1dc99fd38e678e091a1d141d741328f0dec1756a
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2013-10-26 17:25:23 -04:00
Matthias Sohn 401212de7a Add describe command to JGit command line interface
Change-Id: I1560fd2be417361b3d2df15a27618053031bd873
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2013-10-11 00:52:11 +02:00
Jonathan Nieder 1153a59e38 Add support for "jgit archive --output=<filename>"
If the --format option is not given and the output filename is,
then infer the format from that filename.  Otherwise match
"git archive" by defaulting to tar (this is a change from the
existing "jgit archive" default behavior, which was to default to
zip).

Change-Id: I5806bc48a403d05e4cfc3c180b82b33ad7cfae7f
2013-06-06 18:39:07 -07:00
Jonathan Nieder ebfe85d037 Add long filename, large file, and non-ASCII filename support to TarFormat
Attempts to write entries with too-long filenames currently error out:

  $ jgit.pgm/target/jgit archive HEAD >test.tar
  java.lang.RuntimeException: file name 'org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java' is too long ( > 100 bytes)
          at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.putArchiveEntry(TarArchiveOutputStream.java:288)
          at org.eclipse.jgit.archive.TarFormat.putEntry(TarFormat.java:92)
          at org.eclipse.jgit.archive.TarFormat.putEntry(TarFormat.java:62)
          at org.eclipse.jgit.api.ArchiveCommand.writeArchive(ArchiveCommand.java:293)
          at org.eclipse.jgit.api.ArchiveCommand.call(ArchiveCommand.java:322)
          at org.eclipse.jgit.pgm.Archive.run(Archive.java:97)
          at org.eclipse.jgit.pgm.TextBuiltin.execute(TextBuiltin.java:174)
          at org.eclipse.jgit.pgm.Main.execute(Main.java:213)
          at org.eclipse.jgit.pgm.Main.run(Main.java:121)
          at org.eclipse.jgit.pgm.Main.main(Main.java:95)

That's because the default longFileMode is LONGFILE_ERROR, which
throws an exception for filenames longer than 100 characters.  Switch
to LONGFILE_POSIX.  While at it, handle large files and filenames with
strange encodings, too.

This requires commons compress 1.4, which introduced support for large
files and POSIX long filenames.

Change-Id: I04d5427eec0968b129f55d7a4c6021039a494828
2013-06-06 12:31:46 -07:00
Jonathan Nieder d4932620e0 ArchiveCommand: make archive formats non-inner classes
First step toward making ArchiveCommand itself format-agnostic.

Change-Id: I3cff5fce28fa7a19e34f8291cfb5b62f16429713
2013-05-23 18:08:35 -07:00
Matthias Sohn f2d0b50e0a Fix line endings
Change-Id: I61c9c173237a535da8576a9299bfd4bb29e8f56b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2013-05-03 16:19:07 +02:00
Robin Stocker a50ed5666f status: Print conflict description for unmerged paths
Prefix unmerged paths with conflict description (e.g. "both modified:"),
the same way C Git does.

Change-Id: I083cd191ae2ad3e2460aa4052774aed6e36c2699
2013-04-19 19:55:24 +02:00
Matthias Sohn aa7be667bc Make recursive merge strategy the default merge strategy
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>
2013-04-15 21:46:12 +02:00
Tomasz Zarna 5453585773 Add the no-commit option to MergeCommand
Added also tests and the associated option for the command line Merge
command.

Bug: 335091
Change-Id: Ie321c572284a6f64765a81674089fc408a10d059
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2013-04-04 15:11:49 +02:00
François Rey 741ecf56b7 New functions to facilitate the writing of CLI test cases
Writing CLI test cases is tedious because of all the formatting and
escaping subtleties needed when comparing actual output with what's
expected. While creating a test case the two new functions are to be
used instead of the existing execute() in order to prepare the correct
command and expected output and to generate the corresponding test code
that can be pasted into the test case function.

Change-Id: Ia66dc449d3f6fb861c300fef8b56fba83a56c94c
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2013-03-27 09:26:13 -04:00
Jonathan Nieder 78009782cd archive: Add tar support
Unlike ZIP files, tar files do not treat symlinks as ordinary files
with a different mode, so tar support involves a little more code than
would be ideal.

Change-Id: Ica2568f4a0e443bf4b955ef0c029bc8eec62d369
2012-12-04 15:37:42 -08:00
Jonathan Nieder 7123cbf470 archive: Record executable and symlink bits
Setting the mode for a zip entry is now as simple as
"entry.setUnixMode(mode)", so do that.

The test checks using the system's "zipinfo" command (from InfoZIP)
that the mode has been recorded correctly on systems that happen to
have a "zipinfo" command, using org.junit.Assume to distinguish them.

Change-Id: I4236c102fd76f18d01b2dc926eeb9b9fa11a61b7
2012-12-04 15:34:07 -08:00
Jonathan Nieder c9a857a60a Add basic "jgit add" tests
Change-Id: I056c2556c7db98bf57e2527dec11af7c3daf472a
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-11-29 16:38:07 -08:00
Jonathan Nieder 6a94f027b6 Add "jgit archive" tool that writes a tree as a ZIP file
C Git's "git archive" command represents a tree object using a
standard archival format like tar, zip, or tgz, ready for consumption
by other, git-unaware users or tools.

Add a bare-bones analagous "jgit archive" command to show what is
possible, supporting only ZIP format for now.  It uses java.util.zip
which is not aware of the InfoZIP extensions for representing symlinks
and file permissions, so symlinks, executable files, and submodule
entries are represented as plain text files.

Making this functionality available from the library, improving
handling of special entries, and support for other output formats are
left for later patches.  Ultimately the intent is to offer a
TreeArchiveStream class for use by web frontends like Gitiles to offer
"download as zip/tgz/txz" links and use by, for example, code search
tools to get easy access to the content of git tree objects.

Test with "jgit archive my-favorite-tree >out.zip".

Change-Id: Ib590f173ceff3df4b58493cecccd6b9a1b355e3d
2012-11-16 16:21:25 -08:00
Tomasz Zarna fb33e80218 Add reflog command to JGit CLI
Bug: 394497
Change-Id: Ib8bc1d9fd789d22fe5f10e03068a11cfdd3e46eb
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-11-16 12:02:28 -08:00
Tomasz Zarna 318f3d4643 Add support for --no-ff while merging
Bug: 394432
Change-Id: I373128c0ba949f9b24248874f77f3d68b50ccfd1
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-11-16 11:04:13 +01:00
Tomasz Zarna cb0f0ad4cf Add a test for org.eclipse.jgit.pgm.Tag
The test checks if an error is thrown when trying to create the same tag
for the second time.

Change-Id: I4ed2f6c997587f0ea23bd26a32fb64a2d48a980e
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-11-15 16:28:02 -08:00
Tomasz Zarna 790126c145 Do not fail when checking out HEAD
Change-Id: I99f5467477ed53101121a5a5d8a0910c55758401
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-11-15 16:05:09 -08:00
Tomasz Zarna 074f9194dc Prefix an abnormal CLI command termination with 'fatal:'
Change-Id: I3d257666c6fbed7b238c575808f73ec518e811b9
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-11-15 15:45:35 -08:00
Tomasz Zarna e8c25a1738 Add --squash option to org.eclipse.jgit.pgm.Merge
Change-Id: Ifd20b6f4731cfa71319145cac7b464aa53db18b8
2012-10-07 23:38:34 +02:00
Tomasz Zarna f7b644df66 Add tests for output result of merging -- org.eclipse.jgit.pgm.Merge
Change-Id: I888c7e80503b869d65a9617e6a07e01d1ff5f197
2012-09-17 07:07:00 -07:00
Robin Rosenberg 5f094154dd Added new Status CLI command 'jgit status'
This is a first basic implementation that displays current branch and
list of files of various status, but isn't as refined as its native
counterpart (e.g. does not say if we're ahead or behind the remote).
It's been helpful in the diagnostic of bug #347885.

Bug: 348318
CQ: 6769
Change-Id: Ifc35da608fbba652524c1b5b522e3c0d5369ad5e
Signed-off-by: François Rey <eclipse.org@francois.rey.name>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2012-09-09 21:10:59 +02:00
Tomasz Zarna e44c3e7139 Output result of switching branch -- o.e.jgit.pgm.Checkout
Change-Id: I9829950b686ce3b8c70b8f7a1774d5e2b55cd00a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-05 07:59:37 +02:00
Robin Rosenberg dccad56c9a Set core.precomposeunicode to true when creating repository on Mac
Java has no option but to use precomposed Unicode, so we should
state that when creating a new repository. Not that Java will use
precomposed unicode regardless of this setting, but this reduces
the risk of incompatibility with C Git.

Change-Id: I3779b75f76d2e2061c836cbc9b4b7c2ae0cf18f4
2012-08-22 00:36:11 +02:00