1

We have a git repository in which a sub folder holds a flutter app:

project/.git
project/app/*
project/backend/*

Now I would like to bundle some files of the .git folder in the app:

# pubspec.yaml
  assets:
    - ../.git/HEAD
    - ../.git/ORIG_HEAD
    - ../.git/refs/heads/

This works when running on an emulator:

// somewhere in the app:
final _head = await rootBundle.loadString('../.git/HEAD');

But when building the app in release mode, the files are not bundled what perfectly makes sense - but I wonder how we can copy/bundle the files.

My naive approach would be to run a script that copies the files to the app folder, but that is brittle as we need to remember to run the script before each build. What would be a more consistent approach?

Stuck
  • 11,225
  • 11
  • 59
  • 104

1 Answers1

0

I am not sure if this works under windows, but for Linux we can use a symbolic link.

Create a symbolic link for the files that should be bundled in (for example) project/app/assets/git/*:

#!/bin/bash
mkdir -p project/app/assets/git/refs
cd project/app/assets
ln -s ../../../.git/HEAD git/HEAD
ln -s ../../../.git/ORIG_HEAD git/ORIG_HEAD
ln -s ../../../../.git/refs/heads git/refs/heads

Use it in pubspec.yaml:

  assets:
    # Note that the `assets/git/**` files are symbolic link to the actual files in `../.git`
    - assets/git/HEAD
    - assets/git/ORIG_HEAD
    - assets/git/refs/heads/

Read on here to understand how git handles symbolic links when adding them to the repository.

Stuck
  • 11,225
  • 11
  • 59
  • 104