File Exchange

image thumbnail

JGit4MATLAB

version 1.18.0.0 (94.5 KB) by Mark Mikofski
JGit4MATLAB is a wrapper for JGit in MATLAB. It is meant to be used from the MATLAB command window.

2 Downloads

Updated 14 Oct 2013

View Version History

View License

JGit4MATLAB is a wrapper for JGit (http://www.eclipse.org/jgit/) in MATLAB. It is meant to be used in the MATLAB command window.

Installation:
Download the full zip-file from MATLAB Central File Exchange, extract anywhere on your MATLAB path and type jgit. This will download the latest version of org.eclipse.jgit and edit your Java class path file called javaclasspath.txt in the MATLAB preferences directory, making a copy called javaclasspath.txt.JGitSaved of javaclasspath.txt if it already exists.

After this you must restart MATLAB for the changes to your MATLAB Java static class path to take effect.

Create your ssh keys using putty gen and convert them to OpenSSH format. If you set a passphrase, save it in %HOME%\.jsch-userinfo using

>> jgit saveSSHpassphrase <passphrase>

You can set and get global gitconfig name and email using

>> jgit setUserInfo <name> <email@address>

Usage:
In general usage is the same as in Git. See http://git-scm.com/docs.

>> jgit <command> [<options>...] [<args>...] [--] [<args>...]

See all commands

>> jgit help

Get help for individual command

>> jgit help <command>

There are some built in aliases.
co = checkout, ci = commit, st = status, br = branch

Known issues:
There is no mergetool. When a conflict occurs on either pull or merge, the conflicting files will be saved as *.BASE, *.LOCAL, *.REMOTE and *.orig. Download Meld (https://code.google.com/p/meld-installer/) or P4Merge (http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools). Then use the *.BASE, *.LOCAL and *.REMOTE files to resolve the conflict and save the file using its name. As an alternative just use the Git conflict markers to resolve the conflict and save the file.

In order to mark the conflict as resolved, you must first add the file to the index. Then commit.

>> jgit add resolved-conflict-file1 ...
>> jgit commit

Unfortunately, you can not use the --all flag with commit to mark a conflict as resolved. This is a feature that I have not yet implemented issue #7 (see https://github.com/mikofski/JGit4MATLAB/issues/7).

Also there is no way to abort a merge without using the org.eclipse.jgit.api.Git reset command.

>> git = JGit.getGitAPI % get an instance of the JGit api
>> repo = git.getRepository % get an instance of the repository
>> state = repo.getRepositoryState % get the repository state
>> MERGING = org.eclipse.jgit.lib.RepositoryState.MERGING % an enumeration (a constant)
>> resetCMD = git.reset; % get a reset command object
>> HARD = javaMethod('valueOf','org.eclipse.jgit.api.ResetCommand$ResetType','HARD'); % a constant
>> if state.equals(MERGING),resetCMD.setMode(HARD).call,end % check if merging then abort

See issue #10 (https://github.com/mikofski/JGit4MATLAB/issues/10).

Documentation:
http://mikofski.github.io/JGit4MATLAB/

Report Bugs:
https://github.com/mikofski/JGit4MATLAB/issues

References:
http://download.eclipse.org/jgit/docs/latest/apidocs/org/eclipse/jgit/api/Git.html

Cite As

Mark Mikofski (2020). JGit4MATLAB (https://www.mathworks.com/matlabcentral/fileexchange/41348-jgit4matlab), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Mark Mikofski

Shawn Pearce, the author of JGit has died. There is a go fund me for his wife and children. https://www.gofundme.com/shawn-pearce-memorial-fund

Mark Mikofski

**Quick Tip:** Use `>> jgit update` to download the latest version of JGit. The older version is archived in the folder called `older-versions/` and the file `version` is updated with the latest version number. Then restart MATLAB for the update to take effect.

Mark Mikofski

Another interesting mergetool is DiffMerge (http://www.sourcegear.com/diffmerge/) it has a standalone executable - select download from menu at left then select the Windows zip file and download/extract, start sgdm.exe - Voila! It's also available for other platforms. Unfortunately they a freemium model that has a registration pop-up, so this may not be the best option. Do you use JGit4MATLAB? Do you have any mergetool suggestions?

Mark Mikofski

fixed bug #21 (https://github.com/mikofski/JGit4MATLAB/issues/21), available at Github. Do you use JGit4MATLAB? What features are you missing? Have you found bugs? Report them at Github (https://github.com/mikofski/JGit4MATLAB/issues)

Mark Mikofski

Another possible mergetool is WinMerge - http://winmerge.org/ - it also is available as standalone exe, select download tab and look for "binaries" and download/extract zip file. I actually like this one better, it has generate-patch and open conflicted file functions - wonder if it can interpret Git conflict markers? Do you use JGit4MATLAB? What mergetool(s) would you like to see integrated?

Zoe

Mark Mikofski

This is version 0.6 (Falcon)
+ It allows (subset of) Git syntax to be used.

EX1: jgit add file1 file2

EX2: jgit commit -m 'enter msg in single quotes'

EX3: jgit pull

EX4: jgit push origin feature

+ Bugs fixes.
+ `javaclasspath.txt` is now in prefdir instead of userpath (thanks Volker).
+ Merge conflicts also output *.BASE, *.LOCAL, *.REMOTE and *.orig for use in merge tools such as meld and p4m.
+ Documentation is now at http://mikofski.github.io/JGit4MATLAB/.

Please submit bugs to https://github.com/mikofski/JGit4MATLAB.

Enjoy!
--Mark

Mark Mikofski

Just wanted to post an update - I have made some major improvements to JGit4MATLAB. Now it can use SSH passphrases (or not), and can pull, push and fetch. I put utilities in to change or view global config and to save your passphrase. Still more to come! Also check out new website: http://mikofski.github.io/JGit4MATLAB/.

Mark Mikofski

See the recent post on JGit and JGit4MATLAB @ http://undocumentedmatlab.com/blog/jgit-matlab-integration/

Mark Mikofski

download the latest JGit 3.0.0.201306101825-r by using<br/>
>> JGit.downloadJGitJar('path\to\JGIT4MATLAB\@JGit\org.eclipse.jgit.jar')
<br/>
e.g.:<br/>
>> JGit.downloadJGitJar('@JGit\org.eclipse.jgit.jar')
<br/>
Version: 3.0.0.201306101825
<br/>
then restart matlab

Mark Mikofski

Hi Muthu, Thanks for the comment. I have added a function, lowercase "jgit.m" one level up and in the same namespace as @JGit so you should be able to just use the command interface that you describe if you put the toplevel (JGit4MATLAB) on your path.

EG: if JGit4MATLAB is on your path, and this is your file structure:

JGit4MATLAB/
\__jgit.m
..\__@JGit/
...\__JGit.m
....\__status.m
.....\__etc. (other methods in class "@" folder)

then you should be able to call the functions without strings as in your examples:

>> jgit status
# On branch master
nothing to commit, working directory clean

>> jgit branch list
gitCheckout
* master

>> jgit checkout gitCheckout

>> jgit status
# On branch gitCheckout
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# jgit.misc
#
# no changes added to commit (use "git add" and/or "git commit -a")

Is this what you are talking about? If not let me know, and thanks again for your feedback!

BTW: the @folder issue was resolved in the 2013-05-28 update.

Muthu Annamalai

MATLAB has nice feature of supporting both command and functional interface.
i.e. >> disp('hello-world')
%works as well as,
>> disp hello-world

You may want to improve the command interface to JGIT, since most of the arguments are strings, we don't need to call it explicitly that way.

Mark Mikofski

Sorry, folks, I accidentally zipped this up wrong last time, skipping the @JGit folder which is kind of important. I've uploaded a new submission but in the meantime just unzip or copy the contents to a folder on your path called @JGit.

Mark Mikofski

FYI:
All commands that deal with remotes and that require authentication, EG: CLONE, FETCH, PULL, PUSH, will *only* work
* with SSH
* with *no* passphrase
* with keys in the openSSH format
* with keys and known hosts in $HOME\.ssh

Obviously remotes that do not require authentication will work fine. EG: public, read-only and local repositories.

SSH is very easy to set up.
1. Download puttygen (Intel x86) from this site:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Disregard the "Intel x86" business, it doesn't matter what processor you have or whether your os is 64-bit or 32-bit. Puttygen is a very mature well establish application that is used by many other applications, for example all of the TortoiseXXX scm clients use Putty, Plink and Pageant
This is the actual download here: (click to download then click to install)
http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe
2. create a folder called .ssh in your %USERPROFILE%. On Windows 7 this is
C:\Users\<your account name>
and on xp it is
C:\Documents and Settings\<your account name>
You can do this in matlab.
>> mkdir(fullfile(getenv('userprofile'), '.ssh'))
3. create a key using puttygen, this is fairly self explantory, and kind of fun, but do *not* set a passphrase; leave those fields blank!
4. using puttygen, find the conversion menu tab and export the key in the openSSH format to the .ssh folder you created earlier.
5. now copy and paste your public key to your remote repositories (Github, Bitbucket, etc.) as needed. Jsch, which is the ssh client that JGit uses should now work out of the box.

Unfortunately using https isn't possible with JGit4MATLAB. Sorry. but hopefully you'll love the excitement of using ssh key pairs!

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!