-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix "There are uncommitted changes" error messages when using mastodon-git with maston (core) 1.0.0-SNAPSHOT-31 #23
Changes from 2 commits
5d4a1d9
3f9ec0f
785ff77
4905225
8c4998c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -42,7 +42,6 @@ | |||||||||||
import org.eclipse.jgit.api.Git; | ||||||||||||
import org.eclipse.jgit.api.ListBranchCommand; | ||||||||||||
import org.eclipse.jgit.api.ResetCommand; | ||||||||||||
import org.eclipse.jgit.api.errors.GitAPIException; | ||||||||||||
import org.eclipse.jgit.lib.BranchConfig; | ||||||||||||
import org.eclipse.jgit.lib.ConfigConstants; | ||||||||||||
import org.eclipse.jgit.lib.Ref; | ||||||||||||
|
@@ -79,6 +78,10 @@ public class MastodonGitRepository | |||||||||||
|
||||||||||||
private static final PersistentCredentials credentials = new PersistentCredentials(); | ||||||||||||
|
||||||||||||
private static final String MASTODON_REMOTE_DATA_FOLDER = "mastodon.remote"; | ||||||||||||
|
||||||||||||
private static final String MASTODON_PROJECT_FOLDER = "mastodon.project"; | ||||||||||||
|
||||||||||||
private final ProjectModel projectModel; | ||||||||||||
|
||||||||||||
private final File projectRoot; | ||||||||||||
|
@@ -114,21 +117,26 @@ public static MastodonGitRepository shareProject( | |||||||||||
.setCredentialsProvider( credentials.getSingleUseCredentialsProvider() ) | ||||||||||||
.setDirectory( directory ) | ||||||||||||
.call(); | ||||||||||||
final Path mastodonProjectPath = directory.toPath().resolve( "mastodon.project" ); | ||||||||||||
final Path mastodonProjectPath = directory.toPath().resolve( MASTODON_PROJECT_FOLDER ); | ||||||||||||
if ( Files.exists( mastodonProjectPath ) ) | ||||||||||||
throw new MastodonGitException( "The repository already contains a shared mastodon project: " + repositoryURL ); | ||||||||||||
Files.createDirectory( mastodonProjectPath ); | ||||||||||||
|
||||||||||||
Path remoteFolder = directory.toPath().resolve( MASTODON_REMOTE_DATA_FOLDER ); | ||||||||||||
if ( Files.exists( remoteFolder ) ) | ||||||||||||
throw new MastodonGitException( "The repository already contains a shared mastodon project: " + repositoryURL ); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You misunderstood the code here. The user has to select an empty directory and an empty git repository in order to share a project. This message is shown if the repository is not empty. I will change the text to:
Suggested change
|
||||||||||||
Files.createDirectory( remoteFolder ); | ||||||||||||
|
||||||||||||
ProjectSaver.saveProject( mastodonProjectPath.toFile(), projectModel ); | ||||||||||||
Files.copy( mastodonProjectPath.resolve( "gui.xml" ), mastodonProjectPath.resolve( "gui.xml_remote" ) ); | ||||||||||||
Files.copy( mastodonProjectPath.resolve( "project.xml" ), mastodonProjectPath.resolve( "project.xml_remote" ) ); | ||||||||||||
Files.copy( mastodonProjectPath.resolve( "dataset.xml.backup" ), mastodonProjectPath.resolve( "dataset.xml.backup_remote" ) ); | ||||||||||||
copyXmlsFromTo( mastodonProjectPath, remoteFolder ); | ||||||||||||
final Path gitignore = directory.toPath().resolve( ".gitignore" ); | ||||||||||||
|
||||||||||||
Files.write( gitignore, "/mastodon.project/gui.xml\n".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND ); | ||||||||||||
Files.write( gitignore, "/mastodon.project/project.xml\n".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND ); | ||||||||||||
Files.write( gitignore, "/mastodon.project/dataset.xml.backup\n".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND ); | ||||||||||||
git.add().addFilepattern( ".gitignore" ).call(); | ||||||||||||
git.commit().setMessage( "Add .gitignore file" ).call(); | ||||||||||||
git.add().addFilepattern( "mastodon.project" ).call(); | ||||||||||||
git.add().addFilepattern( MASTODON_REMOTE_DATA_FOLDER ).addFilepattern( MASTODON_PROJECT_FOLDER ).call(); | ||||||||||||
git.commit().setMessage( "Share mastodon project" ).call(); | ||||||||||||
git.push().setCredentialsProvider( credentials.getSingleUseCredentialsProvider() ).setRemote( "origin" ).call(); | ||||||||||||
git.close(); | ||||||||||||
|
@@ -161,19 +169,25 @@ public static void cloneRepository( final String repositoryURL, final File direc | |||||||||||
.setDirectory( directory ) | ||||||||||||
.call()) | ||||||||||||
{ | ||||||||||||
final Path mastodonProjectPath = directory.toPath().resolve( "mastodon.project" ); | ||||||||||||
Files.copy( mastodonProjectPath.resolve( "gui.xml_remote" ), mastodonProjectPath.resolve( "gui.xml" ) ); | ||||||||||||
Files.copy( mastodonProjectPath.resolve( "project.xml_remote" ), mastodonProjectPath.resolve( "project.xml" ) ); | ||||||||||||
Files.copy( mastodonProjectPath.resolve( "dataset.xml.backup_remote" ), mastodonProjectPath.resolve( "dataset.xml.backup" ) ); | ||||||||||||
final Path mastodonProjectPath = directory.toPath().resolve( MASTODON_PROJECT_FOLDER ); | ||||||||||||
final Path remoteFolder = directory.toPath().resolve( MASTODON_REMOTE_DATA_FOLDER ); | ||||||||||||
copyXmlsFromTo( remoteFolder, mastodonProjectPath ); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
private static void copyXmlsFromTo( final Path from, final Path to ) throws IOException | ||||||||||||
{ | ||||||||||||
Files.copy( from.resolve( "gui.xml" ), to.resolve( "gui.xml" ) ); | ||||||||||||
Files.copy( from.resolve( "project.xml" ), to.resolve( "project.xml" ) ); | ||||||||||||
Files.copy( from.resolve( "dataset.xml.backup" ), to.resolve( "dataset.xml.backup" ) ); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Simply starts a new Mastodon window with the project in the given repository. | ||||||||||||
*/ | ||||||||||||
public static void openProjectInRepository( final Context context, final File directory ) throws Exception | ||||||||||||
{ | ||||||||||||
final String mastodonFile = directory.toPath().resolve( "mastodon.project" ).toString(); | ||||||||||||
final String mastodonFile = directory.toPath().resolve( MASTODON_PROJECT_FOLDER ).toString(); | ||||||||||||
final boolean restoreGUIState = true; | ||||||||||||
final boolean authorizeSubstituteDummyData = true; | ||||||||||||
final ProjectModel newProject = ProjectLoader.open( mastodonFile, context, restoreGUIState, authorizeSubstituteDummyData ); | ||||||||||||
|
@@ -187,7 +201,7 @@ public synchronized void commitWithoutSave( final String message ) throws Except | |||||||||||
{ | ||||||||||||
try (final Git git = initGit()) | ||||||||||||
{ | ||||||||||||
git.add().addFilepattern( "mastodon.project" ).call(); | ||||||||||||
git.add().addFilepattern( MASTODON_PROJECT_FOLDER ).call(); | ||||||||||||
final CommitCommand commit = git.commit(); | ||||||||||||
commit.setMessage( message ); | ||||||||||||
commit.setAuthor( settingsService.getPersonIdent() ); | ||||||||||||
|
@@ -480,7 +494,7 @@ public synchronized void reset() throws Exception | |||||||||||
|
||||||||||||
private Git initGit() throws IOException | ||||||||||||
{ | ||||||||||||
final boolean correctFolder = projectRoot.getName().equals( "mastodon.project" ); | ||||||||||||
final boolean correctFolder = projectRoot.getName().equals( MASTODON_PROJECT_FOLDER ); | ||||||||||||
if ( !correctFolder ) | ||||||||||||
throw new MastodonGitException( "The current project does not appear to be in a git repo." ); | ||||||||||||
final File gitRoot = projectRoot.getParentFile(); | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.