← Back to blogYouTube Video

Published December 28, 2025

Syncing projects with Google Drive - Part 18 (Connecting the new gitignore parser)

Part 18 of 19 in Syncing Projects with Google Drive

Can't play the video or having issues? Here's the direct link.

Summary

I connect my custom gitignore parser to DriveSinker's sync algorithm by replacing the old ignore checks with a single GitIgnore.shouldIgnore call. I refactor the file-counting and folder-upload functions to accept the new IgnorePattern list and GitIgnore struct, convert patterns back to strings only where needed, and handle ignored directories with filepath.SkipDir while ignored files return nil. After testing, the logs show almost every file skipped except the changed log file and the sync file I had just edited, confirming the new parser works with complicated patterns.

Key takeaways

  • Centralize ignore decisions in GitIgnore.shouldIgnore and call it from both file counting and folder traversal instead of duplicating ignore logic.
  • Pass the GitIgnore struct pointer into sync functions rather than passing the raw ignore list separately.
  • Convert IgnorePattern values back to plain strings only when a function still requires strings, such as building parsed ignores for existing loops.
  • Return filepath.SkipDir for ignored directories and nil for ignored files so traversal stops correctly without uploading skipped content.
  • Check the log file when testing skips, because progress bars can hide the per-file skip messages you need to verify behavior.
  • Test the integrated parser with complicated patterns to confirm the new shouldIgnore path handles more than simple filenames.

Description

We spent the last couple videos building our own custom gitignore parser. In this video, we're finally going to connect it to our sync algorithm. Let's do this. :)

Transcript

Okay, guys, welcome back to the DriveSinker project. In the previous video, we built this `shouldIgnore` function over here in the `GitIgnore` struct, and this is basically going to tell us whether we can ignore a file or we should upload it or whatever, right? And now that we've written this function, we are basically done with the new Git Ignore parser, and now we can actually start to integrate it with our synchronizing algorithm over here. So, as you can see, there's already a couple of errors over here in this file because we're now using the list of Git Ignore patterns instead of using a list of strings. We're going to need to do a bit of refactoring over here to make this entire algorithm more compatible with our new ignore pattern struct. First thing I'm going to do is, over here, let's go and create a new variable called `gitIgnore`, and here we will actually create our new `GitIgnore` struct. We'll pass in our folder, we'll pass in the global ignore, which will be in `.drb.config.ignore`. We'll also pass in the `readGitIgnore` boolean, which should be in our config over here. And then we don't need any of this code anymore, so we can just comment it out. And over here in the `countTotalFiles` function, we can pass in `gitIgnore.toIgnore`. Now, this is a list of ignore patterns, not a list of strings, so we do need to refactor this function to accept a list of ignore patterns instead of strings. Now, the first thing we need to do is up here, create a list of parsed ignores because we want to convert this into a list of strings. We say make a list of strings with a capacity of zero or a length of zero, but a capacity of the length of the `toIgnore` list. And then we just loop over the `toIgnore` list, and we'll say `parsedIgnores.append(pattern.pattern)`. There we go. And then over here in this for loop over here, we'll just pass in `parsedIgnores` instead of `toIgnoreList`. Now, instead of looping over the entire ignore list anymore, what we can do is, and also, let's also pass in the `GitIgnore` struct over here as a pointer because we are going to need it. And then instead of this entire loop over the ignore list, what we can do is we can just say `switch gitIgnore.shouldIgnore` and pass in the path over here along with the dir entry as well. And then let's say if this upload is allowed, then we should just append total files, right? Because we are going to upload this because the upload is allowed. Otherwise, if the return type is `IgnoreDir`, we can just return `filepath.SkipDir`. And if it is `IgnoreFile`, then you can just return nil and move on to the next path, right? And then we don't need any of this code either, so we can just remove it completely. And over here, let's just add a default case, like `default: return nil`, just so we satisfy the error. And okay, apparently that doesn't work either. So instead of this, let's just add a `return nil` outside over here, and that should make that error go away. And make sure to pass that in over here as such. You know, one more thing that I just realized over here: if we're passing the entire `GitIgnore` struct over here, we don't need to pass in the ignore list separately, right? What we can do is we can remove this and go back over here and remove this `toIgnore` from the arguments list because we're not even using it anymore, right? So back in the `uploadFolder` function, now down here, instead of this complicated ignore logic that we previously had, all we can all we just need to say now is `gitIgnore.shouldIgnore`, passing the path, passing the dir entry, and then just say `case Ignored: return filepath.SkipDir`, `case IgnoreFile: return nil`. And just with those five or six lines of code, we have implemented the entire Git Ignore logic that we just built in the past two, three, whatever videos. Now, before testing this out, I'm going to go over to the `uploadFile` function. I'm just going to comment out these logs just for now because I just want to see the logs of skipping files and folders, right? Just so I know that it's actually working. And we're going to have to replace this response variable with an underscore just so Go stops complaining at me. This is just for testing, guys. Now, let's see what happens if I actually run this with the new Git Ignore logic. Okay, so apparently we were using progress bars and not the actual logs, so the logs should be in the log file over here. Let's just go and look at them over here. So these are all the logs for this current upload. As you can see, it pretty much skipped most of the files over here. Yeah, it pretty much skipped almost every file over here except for, I guess, the progress bar, which was changed, the log file, which obviously got changed because we're running the program and it's outputting some logs, the sync file, which we literally just wrote code for it right here. Other than that, it just skipped basically everything. So no extra file was uploaded over here. So, yeah, that's the new Git Ignore parser. It works, and you can also put all sorts of complicated patterns over here, right? Because we've actually added support for all of them over here. So, yeah, that works, and I'm going to stop the video over there, guys. Thank you for watching. Like, comment, subscribe. We've made a ton of progress in this project, so if you're following along so far, thank you. And, yeah, we'll see what we build next time. Quick self-promo plug: this is my professional website, and I'm a freelance developer who makes web and mobile apps for people. If this is something you're interested in, if you want to hire a developer to work on a project, or if you know someone who wants to hire a developer to work on some project, then go to the top link in the description and book a call with me. It's completely free. We'll talk about your project, we'll see what's what, and we'll start working together to make it a reality, if that's something you're interested in. Top link in the description. Other than that, thank you for watching the video, and I'll see you in the next one.

Share this article

Hassan Aziz pointing up

Dude, you’re at the bottom of my landing page.

Just book a call already if you’re that interested.

You scrolled all the way here.