Konstanius / MineCICD

Git for Minecraft Servers! Track changes, speed up development, rollback changes, and much more!
12 stars 1 forks source link

Can't add files/folder #10

Open HappyAreaBean opened 1 month ago

HappyAreaBean commented 1 month ago

Hello, when I use /minecicd add plugins/LuckPerms/config.yml, it does not add any files. It also happened with adding a folder too. It returned the message [MineCICD] Added 0 new file(s) to Git tracking. But when I add bukkit.yml with /minecicd add bukkit.yml it does add the file.


Environment Information:

Plugin Config

```yml git: # Username or token user: "" # Password or token (if using token, use it as both user and pass) pass: "" # Repository URL repo: "" # Selected branch, default is master or main # Use this to set up development servers, production servers, and test servers and the like # This has an effect on everything from pushing, pulling, and webhooks branch: "master" # Whether experimental jar unloading and loading should be enabled # This requires PlugManX to be installed and working on your server # This is experimental and may cause issues! # Will inevitably cause a lot of issues if used on library or core plugins # Requires you to remove "*.jar" from the .gitignore file in your server root experimental-jar-loading: true bossbar: # Whether to enable the boss bar enabled: true # How long the action result should be visible for, in ticks (20 ticks = 1 second) # High values here WILL delay further commands of the same type duration: 100 # Filtering in the config is obsolete with V2 # See the .gitignore file in your server root for filtering # See https://git-scm.com/docs/gitignore for more information webhooks: # Will listen at http://:/ # The port to listen on, set to 0 to disable port: 0 # The path to listen on path: "minecicd" # Webhook listener configuration # minecicd.notify is used for identifying who to notify when a webhook event is received # Order of execution: # 1. Commands / Scripts are executed with operator permissions # 2. One of the following is executed (in this order): # - restart # - global reload # - individual reload allow-commands: true # This allows to execute arbitrary commands on the server, it is recommended to disable this on production servers allow-scripts: true # This allows to execute arbitrary CICD scripts on the server, it is recommended to disable this on production servers allow-individual-reload: true # This might not work with all plugins, issues will be displayed in the console. It is recommended to disable this on production servers allow-global-reload: false # This is highly discouraged, as it can cause issues with many plugins allow-restart: true ```


Side Notes:


Konstanius commented 1 month ago

Could you please provide some information about which operating system this is exactly? And the system architecture as well, please.

HappyAreaBean commented 1 month ago

Sure! I added that information in the first comment. :)

SzczurekYT commented 1 month ago

I seem to be facing the same issue. I added some files, and the ones in the root directory landed on github, while the ones from plugins folder didn't. Running git ignore-check -v on for example bukkit.yml result in no output meaning, that the file is included, but running that on config files of some plugins results in line stating that it is ignored by the global ignore, while there is a negation down the line.

No idea why

SzczurekYT commented 1 month ago

I think I found the source of the problem in git docs.

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. [...]

So these files can't be unignored by ! because their parent directory plugins is already ignored by /*

Konstanius commented 1 month ago

To quote the default .gitignore file from the plugin:

# The .gitignore file for MineCICD.
# By default, ALL files and directories are ignored!
# This serves as a store for what files are added / ignored and may be edited manually or via the plugin.
/*
# MineCICD is priority EXCLUDED. It is not recommended to track it, as this could lead to security risks or other issues
/plugins/MineCICD/**
# The secrets.yml file in the server root should also be excluded, as it contains sensitive information
/secrets.ym**
# The .gitignore is INCLUDED at all times
!/.gitignore
# The MineCICD-(version) jarfile should also be excluded, since tracking it will break the plugin operation
/plugins/MineCICD-*.jar
# PlugManX is also excluded, as it is not recommended to track it
/plugins/PlugManX/**
/plugins/PlugManX-*.jar
/plugins/PlugMan/**
/plugins/PlugMan-*.jar

# Line 10-11 is used for INSERTING new files or directories to be unignored, done by MineCICD!
# MineCICD GITIGNORE PART BEGIN MARKER
# MineCICD GITIGNORE PART END MARKER

# Any manual exclusions / inclusions shall be done below this line
*.png
*.dat
*.log
*.db
*.sql
*.sqlite
*.zip
*.tar
*.gz
*.bz2
*.7z
*.rar
# JAR files are currently only experimentally supported
# See the config option "experimental-jar-loading" and README for more information
*.jar

# The following files and directories are also priority excluded, as they are not recommended to be tracked
/plugins/.paper-remapped/**
/cache/**
/versions/**
/logs/**
/world/**
/world_nether/**
/world_the_end/**
/libraries/**
/usercache.json
/ops.json

By default, ALL files are ignored (/*) However, any file that is added below between the

# MineCICD GITIGNORE PART BEGIN MARKER
# MineCICD GITIGNORE PART END MARKER

will be a negation (!/plugins/negated_file.txt)

As far as I know and confirmed with numerous tests on multiple servers, this architecture seems to be working fine.

Now I am wondering, where you got that quote from? Is it from the official Git documentation? I only found the following on https://git-scm.com/docs/gitignore/en:

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

Konstanius commented 1 month ago

What I meant to say with this, is that ignoring /* will not affect the negation rules that negate anything below, as proven by Git being now able to track the specified file(s). I think there is some other issue that's causing this.

Konstanius commented 1 month ago

Could you share the resulting .gitignore file in your server root, please?

SzczurekYT commented 1 month ago

With this gitignore there is no plugins directory on GitHub.

# The .gitignore file for MineCICD.
# By default, ALL files and directories are ignored!
# This serves as a store for what files are added / ignored and may be edited manually or via the plugin.
/*
# MineCICD is priority EXCLUDED. It is not recommended to track it, as this could lead to security risks or other issues
/plugins/MineCICD/**
# The secrets.yml file in the server root should also be excluded, as it contains sensitive information
/secrets.ym**
# The .gitignore is INCLUDED at all times
!/.gitignore
# The MineCICD-(version) jarfile should also be excluded, since tracking it will break the plugin operation
/plugins/MineCICD-*.jar
# PlugManX is also excluded, as it is not recommended to track it
/plugins/PlugManX/**
/plugins/PlugManX-*.jar
/plugins/PlugMan/**
/plugins/PlugMan-*.jar

# Line 10-11 is used for INSERTING new files or directories to be unignored, done by MineCICD!
# MineCICD GITIGNORE PART BEGIN MARKER
!/plugins/BlueSlimeCore/
!/plugins/BlueSlimeCore.jar
!/plugins/BetterTeams/teampermissions.yml
!/plugins/BetterTeams/team.yml
!/plugins/BetterTeams/pl.yml
!/plugins/BetterTeams/messages.yml
!/plugins/BetterTeams/chestpermissions.yml
!/plugins/BetterTeams/config.yml
!/plugins/BetterTeams.jar
!/plugins/AuthMe/welcome.txt
!/plugins/AuthMe/verification_code_email.html
!/plugins/AuthMe/spawn.yml
!/plugins/AuthMe/recovery_code_email.html
!/plugins/AuthMe/messages/
!/plugins/AuthMe/email.html
!/plugins/AuthMe/commands.yml
!/plugins/AuthMe/config.yml
!/plugins/AnvilClickRepair-1.0.0.jar
!/plugins/CommandAPI/config.yml
!/plugins/CommandAPI/
!/plugins/CommandAPI-9.3.0.jar
!/spigot.yml
!/commands.yml
!/help.yml
!/server.properties
!/version_history.json
!/config/
!/paper.jar
!/bukkit.yml
!/wepif.yml
!/eula.txt
# MineCICD GITIGNORE PART END MARKER

# Any manual exclusions / inclusions shall be done below this line
*.png
*.dat
*.log
*.db
*.sql
*.sqlite
*.zip
*.tar
*.gz
*.bz2
*.7z
*.rar
# JAR files are currently only experimentally supported
# See the config option "experimental-jar-loading" and README for more information
#*.jar

# The following files and directories are also priority excluded, as they are not recommended to be tracked
/plugins/.paper-remapped/**
/cache/**
/versions/**
/logs/**
/world/**
/world_nether/**
/world_the_end/**
/libraries/**
/usercache.json
/ops.json
Konstanius commented 1 month ago

And you did /minecicd add plugins/? Normally, that should only add !/plugins/ to that list

SzczurekYT commented 1 month ago

No, I didn't do that, no one told me to do that. I thought that would recursively add everything in there to be included. Wouldn't it? And that's obviously bad because we want to avoid commiting things like plugin/players data, and only upload the config file / jars.

HappyAreaBean commented 1 month ago

No, I didn't do that, no one told me to do that. I thought that would recursively add everything in there to be included. Wouldn't it? And that's obviously bad because we want to avoid commiting things like plugin/players data, and only upload the config file / jars.

I tried /minecicd add plugins/ before, and yes, you probably don't want to do that it will include everything inside the plugin's folder,

SzczurekYT commented 1 month ago

So do you have any solution for this case @Konstanius ? How can we make this work without commiting unwanted files?

Konstanius commented 1 month ago

Okay this is too through and through, to clear things up we're gonna do 2 things.

Both @SzczurekYT and @HappyAreaBean please provide an accurate report of the following:

  1. What files did you add by using /minecicd add ...
  2. What is the expected file tree on your Git remote repository
  3. What is the actual file tree on your Git remote repository

I will respond tomorrow (CEST) For any other smaller communication, please feel free to add me on Discord (konstanius), as to keep this issue clean and readable.

HappyAreaBean commented 1 month ago

What files did you add by using /minecicd add ...

What is the expected file tree on your Git remote repository

.
├── plugins/
│   └── FantasyMCDevToolbox/
│       └── items/
│           ├── test.txt
│           └── test1.txt
└── .gitignore

What is the actual file tree on your Git remote repository

.
└── .gitignore

圖片

Konstanius commented 1 month ago

This is very odd indeed. Can you try to manually reproduce the steps the plugin would take to add these files to git?

  1. Add a negation rule to .gitignore for the given file
  2. Run git add <file> in a terminal
  3. Commit and push these changes
  4. Check the repository

The result of this tells if either the plugin is the issue or my usage of Git is

HappyAreaBean commented 1 month ago

Where do you want me to add the negation rule in .gitignore? At the top or under the # MineCICD GITIGNORE PART BEGIN MARKER?

Konstanius commented 1 month ago

Directly below the marker, please

HappyAreaBean commented 1 month ago

This is what I received when I used git add plugins/FantasyMCDevToolbox/items/test.txt:

The following paths are ignored by one of your .gitignore files:
plugins
hint: Use -f if you really want to add them.
hint: Disable this message with "git config advice.addIgnoredFile false"

I can only add it by using the -f force flag.

This is the git check-ignore -v plugins/FantasyMCDevToolbox/items/test.txt output too:

.gitignore:4:/* plugins/FantasyMCDevToolbox/items/test.txt

.gitignore file

```.gitignore # The .gitignore file for MineCICD. # By default, ALL files and directories are ignored! # This serves as a store for what files are added / ignored and may be edited manually or via the plugin. /* # MineCICD is priority EXCLUDED. It is not recommended to track it, as this could lead to security risks or other issues /plugins/MineCICD/** # The secrets.yml file in the server root should also be excluded, as it contains sensitive information /secrets.ym** # The .gitignore is INCLUDED at all times !/.gitignore # The MineCICD-(version) jarfile should also be excluded, since tracking it will break the plugin operation /plugins/MineCICD-*.jar # PlugManX is also excluded, as it is not recommended to track it /plugins/PlugManX/** /plugins/PlugManX-*.jar /plugins/PlugMan/** /plugins/PlugMan-*.jar # Line 10-11 is used for INSERTING new files or directories to be unignored, done by MineCICD! # MineCICD GITIGNORE PART BEGIN MARKER !/plugins/FantasyMCDevToolbox/items/test.txt # MineCICD GITIGNORE PART END MARKER # Any manual exclusions / inclusions shall be done below this line *.png *.dat *.log *.db *.sql *.sqlite *.zip *.tar *.gz *.bz2 *.7z *.rar # JAR files are currently only experimentally supported # See the config option "experimental-jar-loading" and README for more information *.jar # The following files and directories are also priority excluded, as they are not recommended to be tracked /plugins/.paper-remapped/** /cache/** /versions/** /logs/** /world/** /world_nether/** /world_the_end/** /libraries/** /usercache.json /ops.json ```

Konstanius commented 1 month ago

Soooo this must mean that Git behaves differently on different platforms? That seems even more odd when considering that the plugin itself used JGit, which doesnt rely on git at all, unless its installed on the computer itself.

I will try to dig further into this.

SzczurekYT commented 1 month ago

For me everything seems to behave correctly, as stated in the doc, on the example provided by @HappyAreaBean He didn't add the plugin/ directory via /git add plugins/, so there is no !/plugins/ line in his .gitignore, which means nothing in the plugins/ directory is included. So this is more of approach / git problem, and not an actual bug in the code. The proper solution would probably be to include the plugins/ directory and then exclude all the unwanted files, instead of trying to do it the other way around - exclude everything, and manually try to include all the important files. This can already be done with the /git remove command, however it would be much easier if we could disable the commit & push behavior of /git add/remove commands, so we can add plugins/, then exclude (remove) the files that keep data, and then commit and push the changes. Otherwise all the data will go to remote on /git add plugins/ and then subsequent commands (and thus commits) will be about removing that, instead of creating one commit with only the data that's needed.

this has turned into a pretty long message, so I hope you can grasp it 🫠