Skip to content
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

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<license.organizationName>Mastodon authors</license.organizationName>
<license.copyrightOwners>Matthias Arzt</license.copyrightOwners>

<mastodon.version>1.0.0-beta-30</mastodon.version>
<mastodon.version>1.0.0-beta-31-SNAPSHOT</mastodon.version>
<mastodon-tomancak.version>0.4.2</mastodon-tomancak.version>
<mastodon-collection.version>1.0.0-beta-26</mastodon-collection.version>

Expand Down Expand Up @@ -156,6 +156,13 @@
<configFile>mastodon-coding-style.xml</configFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx2g</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new MastodonGitException( "The repository already contains a shared mastodon project: " + repositoryURL );
throw new MastodonGitException( "The specified directory already contains a mastodon project: " + repositoryURL + ". Please specify an empty directory.");

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 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new MastodonGitException( "The repository already contains a shared mastodon project: " + repositoryURL );
throw new MastodonGitException( "The specified directory already contains a shared mastodon project: " + repositoryURL + ". Please specify an empty directory.");

Copy link
Collaborator Author

@maarzt maarzt Oct 1, 2024

Choose a reason for hiding this comment

The 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
throw new MastodonGitException( "The repository already contains a shared mastodon project: " + repositoryURL );
throw new MastodonGitException( "The repository already contains a shared mastodon project: " + repositoryURL
+ "\nPlease specify an empty git repository." );

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();
Expand Down Expand Up @@ -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 );
Expand All @@ -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() );
Expand Down Expand Up @@ -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();
Expand Down
Loading