@@ 6,6 6,7 @@ RULES="$3"
CSV_LENGTH_OFFSET="${4:-0}" # Number of lines in the CSV before/after data
CSV_BASENAME="${CSV##*/}"
+CSV_DIRNAME="$(dirname $CSV)"
TMP_DIR="${HOME}/.tmp"
TMP_CSV="$TMP_DIR/$CSV_BASENAME.csv"
@@ 23,6 24,14 @@ duplicates_p () { test ! $(("$JOURNAL_LENGTH" + "$LINES_ADDED_LENGTH" + "$CSV_LE
# Body
+# If csv is a new file, not yet tracked by git, import the whole file.
+if ! $(git cat-file -e HEAD:$CSV 2> /dev/null); then
+ echo -e "$CSV not tracked by git; importing all transactions.\n\n"
+ hledger import -f "$JOURNAL" --rules-file="$RULES" "$CSV"
+ rm -f "$CSV_DIRNAME/.latest.$CSV_BASENAME" # Clean up any .latest files
+ exit 0
+fi
+
# For some reason, hledger import would not import entries from a CSV stored inside /tmp/ on my Debian 11 machine.
# Instead of using a tmp file, it might be preferable if hledger import accepted input from stdin.
mkdir -p "$TMP_DIR"