What is a Bare Repository?

 

🖥️ What is a Bare Repository?

A bare Git repository is a special type of repository that contains only the Git version history and metadata, without a local copy of the actual project files.

FeatureNormal (Non-Bare) RepositoryBare Repository
ContentsThe project's working files (the code you edit) PLUS a hidden .git folder with the history.ONLY the contents of the .git folder (the history).
Working DirectoryYes (You can edit files here).No (You cannot edit files or run the code directly).
PurposeLocal development (cloned by a developer to work on the code).Central coordination (used on a server like GitHub or GitLab to share and synchronize changes among multiple developers).
ConventionThe directory name is the project name (e.g., my-project).The directory name usually ends with .git (e.g., my-project.git).

Analogy: A bare repo is like the main server drive in a library—it holds the master record of all books and revisions, but you don't read or write in that drive. A normal repo is like the local copy you check out to read and make notes in.


🚀 How to Work in Git (The Basic Workflow)

Working in Git involves a three-stage process: your local environment, the staging area, and the repository history.

1. Initialization and Cloning

GoalCommandDescription
Start a NEW projectgit initInitializes a normal repository in the current directory.

Start from a REMOTEgit clone <URL>Downloads an existing (usually bare) repository from a remote server (like GitHub) and creates a normal local repository for you to work in.

2. The Cycle of Saving Changes (Local Work)

This is the core of your day-to-day work in Git.

StageCommandPurpose
WorkEdit files in your project directory.Your files are in the Working Directory. Git knows they're modified.
Checkgit statusShows which files are modified and which are staged for the next commit.
Stagegit add <file> or git add .Moves modified files from the Working Directory to the Staging Area. This marks them for inclusion in the next commit.
Commitgit commit -m "Your descriptive message"Takes a snapshot of everything in the Staging Area and permanently saves it into your local Git Repository History.

3. Sharing Your Changes (Remote Work)

Once you have committed changes locally, you share them with the bare remote repository.

CommandPurpose
git pullFetch changes from the remote repository and automatically Merge them into your current local branch. (Do this before you start new work to ensure you're up-to-date).

git pushUploads your local commits to the remote (bare) repository so your teammates can see them.
Continue Reading...

What is Git ?

 Git is a Distributed Version Control System (DVCS) that is used to track changes in source code (or any set of files) during software development. It enables multiple people to collaborate on a project efficiently without overwriting each other's work and allows developers to revert to any previous version of the code.

Here is an article drafted for your blog to explain Git to a beginner audience.


✍️ Blog Article: Git: Your Project's Time Machine and Collaboration Superpower

Have you ever worked on a document and wished you could revert to a state from three hours ago, or even three weeks ago, without losing any of your current work?

In the world of software development, this ability is not a luxury—it's a necessity. This is where Git comes in.

What Exactly Is Git? 💡

Simply put, Git is a Version Control System (VCS). Think of it as a sophisticated "super save" button for your entire project, but with an exhaustive history log.

Git is specifically a Distributed Version Control System (DVCS), which is a key concept:

  1. Version Control: Git tracks every modification made to your files over time. It saves these changes as snapshots—not just file differences—so you can look back at any point in your project's history, see exactly what was changed, who changed it, and why.

  2. Distributed: Every developer working on the project has a full, local copy of the entire project's history. This means you can work offline, commit your changes, and browse the history without needing to connect to a central server. This is a major reason Git is so fast and reliable.


The Two Core Functions of Git

Git solves two fundamental problems in development: History and Collaboration.

1. The Power of History (Commits)

When you are ready to permanently save a set of changes, you create a commit. A commit is a permanent snapshot of your project at that moment in time, complete with an author, timestamp, and a descriptive message.

  • Never Lose Work: Made a huge mistake? Don't worry. Git allows you to instantly revert back to any past commit, effectively undoing the error without destroying the record of what happened.

  • Audit Trail: Every change is documented. If a bug appears, you can use Git to pinpoint the exact commit that introduced the problem.

2. The Art of Collaboration (Branching)

Branching is arguably Git's most powerful feature. A branch is an independent line of development.

Imagine you need to build a new feature. Instead of working on the main, stable code (often called main or master), you create a new branch.

  • Isolated Workspaces: This new branch is your safe sandbox. You can experiment, break things, and make mistakes without affecting the main project used by others.

  • Seamless Integration: Once your feature is complete and tested, you merge your branch back into the main codebase, combining your changes neatly and efficiently. This allows multiple people to work on different features simultaneously.


Git vs. GitHub (or GitLab/Bitbucket)

This is a common point of confusion for beginners.

TermWhat It IsAnalogy
GitThe software (the tool) that runs locally on your computer to track the history and manage versions.The engine in your car.
GitHubA cloud-based platform (a remote server) that hosts and displays Git repositories online. It adds collaboration features like Pull Requests.The garage where you park your car for everyone to see, or the road network that connects everyone.

You can use Git without GitHub, but you need Git to use GitHub. GitHub (along with its competitors like GitLab and Bitbucket) simply provides a central place for distributed teams to push their local Git copies and synchronize their work.

Ready to Get Started? The Basic Git Workflow

Getting your project under Git's control is simple. Here are the core commands you'll use every day:

  1. git init: Initializes a new local repository in your current folder.

  2. git clone <url>: Downloads a remote repository (from GitHub, etc.) to your local machine.

  3. git add <file>: Stages files, telling Git which changes to include in the next commit.

  4. git commit -m "Your description": Saves the staged changes as a permanent snapshot in your local history.

  5. git push: Sends your new local commits up to the remote repository (e.g., GitHub) to share your work.

  6. git pull: Downloads and integrates the latest changes from the remote repository into your local copy.

Mastering Git is a cornerstone of modern development. It transforms individual coding into synchronized, safe, and powerful teamwork. It's the essential tool for building robust projects—big or small—that stand the test of time and collaboration.

Continue Reading...

Create Custom Snippet VScode

{

"Add Comment": {

  "prefix": "TriComment",

  "body": [

    "//TRI ${1:Your Name here} $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND ${2|+,-,Start,End,++|}"

  ],

  "description": "TRI Add Comment"

 }

}

Continue Reading...

Batch Request in Business Central APIs

 When calling Business Central APIs you do one operation at a time. For example, you can only insert or modify one customer, or create one sales invoice. With deep inserts, it is possible to create header and lines together, and then you can create multiple lines. But that’s only possible on the line records, you still create one header at a time. With a batch request, it is possible to combine multiple operations in one request. The batch request is submitted as a single HTTP POST request to the $batch endpoint and the body contains a set of operations. From an optimization point of view, batching minimizes the number of requests from an API consumer because you combine multiple requests into one.

Batch URL

The $batch endpoint is available on all API endpoints. For the Business Central SaaS environment you can use this URL:

https://{{baseurl}}/api/v2.0/$batch

Everything I describe here also works for custom APIs. The URL will then look like:

https://{{baseurl}}/api/[publisher]/[group]/[version]/$batch

Request headers

Because the request body will be JSON the Content-Type header of the request must be set to appication/json. If the response should be JSON as well (and you want that!), then the Accept header must also be set to application/json. If you leave the Accept header out, then the response will be multipart/mixed. Here is the basic structure of the request, without the body. I leave out the Authorization header, but you need to add that obviously. ðŸ™‚


POST {{baseurl}}/api/v2.0/$batch Content-Type: application/json Accept: application/json

The requests array must contain one ore more operations, and each of them must contains an id, the method and a URL and optionally also headers and a body. Here is an example of an operation to insert a single journal line.

{

"method": "POST",

"id": "r1",

"url": "companies({{companyId}})/journals({{journalId}})/journalLines",

"headers": {

"Content-Type": "application/json"

},

"body": {

        "accountId": "{{accountId}}",

        "postingDate": "2020-10-20",

"documentNumber": "SALARY2020-10",

"amount": -3250,

"description": "Salary to Bob"

}

}



Let’s take the operation above, to insert a single journal line and compose a batch request that inserts multiple journal lines in one go. The request body looks like:

{

  "requests": [

    {

      "method": "POST",

      "id": "r1",

      "url": "companies({{companyId}})/journals({{journalId}})/journalLines",

      "headers": {

        "Content-Type": "application/json"

      },

      "body": {

        "accountId": "{{accountId}}",

        "postingDate": "2020-10-20",

        "documentNumber": "SALARY2020-12",

        "amount": -3250,

        "description": "Salary to Bob"

      }

    },

    {

      "method": "POST",

      "id": "r2",

      "url": "companies({{companyId}})/journals({{journalId}})/journalLines",

      "headers": {

        "Content-Type": "application/json"

      },

      "body": {

        "accountId": "{{accountId}}",

        "postingDate": "2020-10-20",

        "documentNumber": "SALARY2020-12",

        "amount": -3500,

        "description": "Salary to John"

      }

    },

    {

      "method": "POST",

      "id": "r3",

      "url": "companies({{companyId}})/journals({{journalId}})/journalLines",

      "headers": {

        "Content-Type": "application/json"

      },

      "body": {

        "accountId": "{{accountId2}}",

        "postingDate": "2020-10-20",

        "documentNumber": "SALARY2020-12",

        "amount": 6750,

        "description": "Salaries December 2020"

      }

    }

  ]

}

As you can see, each operation has a corresponding result in the response, identified by the id. You should always use the id of the individual operation to find the corresponding result. Don’t assume that the results will always be in the same order as the request! They may seem to be in the same order, but the OData standard describes that the results can be in any order.

Each operation result has a status, which is the HTTP status that you would normally get for a single request. It includes the response headers and response body of the individual operation. The response of the batch request itself will always have status 200 if the server was able to read the batch request. Even if the batch request has operations that couldn’t be processed because of an error condition, the batch response status will still be 200. So don’t only look at the response status of the batch request, you need to read the response body to find out the results of each operation. Only when the batch request body is malformed, or you are not authorized, then the whole batch request will fail and you will get a status 500 (malformed batch request) or status 401 (not authorized).

So far it’s really simple, isn’t it? In the next blog posts in this series, I will cover topics like:

  • What happens if an error occurs in one of the requests
  • Process a batch as one big transaction
  • Combine multiple operations types, like POST and GET
  • Define the order of operations
  • Reduce the size of the response payload



Continue Reading...

Function for Split Text With Maximum Characters Without Damaging Words – AL / C/AL

 local procedure TrySplitTextWithoutDamagingWords(FullText: Text; MaximumCaractorLength:Integer; var MaximumText: Text; var RemainingText: Text) IsRemainingToSplit: Boolean

    var

        SpcPos: Integer;

        MaxSpcPos: Integer;

        CheckText: Text;

    begin

        FullText := DelChr(FullText, '<>', ' ');

        if (FullText = '') or (MaximumCaractorLength = 0) or (StrLen(FullText) <= MaximumCaractorLength) then begin

            MaximumText := FullText;

            RemainingText := '';

            exit(false);

        end;

        MaximumText := CopyStr(FullText, 1, MaximumCaractorLength);

        RemainingText := CopyStr(FullText, MaximumCaractorLength + 1, StrLen(FullText));

        if CopyStr(FullText, MaximumCaractorLength+1, 1)<>' 'then begin

            CheckText := MaximumText;

            repeat begin

                SpcPos := StrPos(CheckText, ' ');

                MaxSpcPos += SpcPos;

                CheckText := CopyStr(CheckText, SpcPos + 1, MaximumCaractorLength);

            end until SpcPos = 0;

            if MaxSpcPos > 0 then begin

                MaximumText := CopyStr(FullText, 1, MaxSpcPos - 1);

                RemainingText := CopyStr(FullText, MaxSpcPos + 1, StrLen(FullText));

            end;

        end;

        exit(StrLen(RemainingText) > MaximumCaractorLength);

    end;

How to use the function?

There are four parameters and a boolean type return value.

  1. Parameter – FullText:
    The text that you want to split. The data type is Text.
  2. Parameter – MaximumCaractorLength:
    Maximum length to split. The data type is Integer.
  3. Parameter – MaximumText:
    The var type parameter that will be assigned split text. The data type is Text.
  4. Parameter – RemainingText:
    The var type parameter that will be assigned remaining text. The data type is Text.
  5. Return Value – IsRemainingToSplit:
    If there is a remaining text exceeding the maximum length it returns true. The data type is Boolean.

Example 1: Single split:

I create three local variables (FullText: Text, SplitText: Text, and RemainingText: Text) and pass them as follows (The maximum character length is 26).

FullText:='NAVUSER is the best site for learning Microsoft Dynamics Navision and Dynamics 365 Business Central.';

TrySplitTextWithoutDamagingWords(FullText,26,SplitText,RemainingText);

Message(SplitText);

FullText:='NAVUSER is the best site for learning Microsoft Dynamics Navision and Dynamics 365 Business Central.';

RemainingText:=FullText;

repeat

     TrySplitTextWithoutDamagingWords(RemainingText,26,SplitText,RemainingText);

     Message(SplitText);

until RemainingText='';

Continue Reading...