An open API service indexing awesome lists of open source software.

https://github.com/td99/gitdiff2docx

Converts git diffs to docx.
https://github.com/td99/gitdiff2docx

docx docx-generator git git-diff github gitlab ipa microsoft-word python word

Last synced: 13 days ago
JSON representation

Converts git diffs to docx.

Awesome Lists containing this project

README

          

# GitDiff2Docx
A Python utility that converts git diffs into formatted Word documents. The tool helps developers and teams document code changes by creating reports from git commit differences.

## Features
- Convert git diffs to formatted DOCX files
- Multilingual support with JSON-based localization
- Customizable fonts and styling for diff content
- Optional line number display
- Color-coded changes (green for additions, red for deletions, gray for context)
- Syntax highlighting
- Support for multiple file changes in a single report
- Configurable defaults via config.json
- Ignore specific files or directories using .gddignore
- Built-in and custom themes

## Installation
1. Clone the repository
2. Install dependencies:
```bash
pip install -r requirements.txt
```

## Usage
Run the script and follow the interactive prompts:
```bash
python diff_tool.py
```

The tool will ask for:
- Path of the target git repository
- Source and target commit hashes (if none entered previously)
- Path of the output DOCX file

Example interaction:
```
< Enter the target Git directory: .
< Enter the first commit hash (optional):
< Enter the last commit hash (optional):
< Enter the output .docx file path (e.g., output.docx): ./test.docx
```
If no commit hashes are provided, the tool automatically compares the latest commit (HEAD) with its predecessor.

## Output Format
The generated DOCX includes:
- Title with commit range
- Section for each changed file
- Color-coded diff tables
- Custom font styling
- Image support
- Syntax highlighting

## Configuration
GitDiff2Docx can be customized using a `config.json` file placed in the same directory as `diff_tool.py`.

### Themes
- Theme files are loaded from the `themes/` folder.
- Set `"theme": ""` in `config.json` (without `.json`).
- Built-in themes are `classic`, `modern`, `modern-atlas`, `modern-carbon`, `modern-sand`, and `modern-dark`.
- Add your own theme by creating `themes/.json`.
- Optional global overrides can be applied by creating `themes/_overrides.json`.
- Overrides are deep-merged into the selected theme, so only provided subkeys are replaced.
- Theme-level font settings are available via `font.name` and `font.size` (applies to code tables only).
- Theme-level border settings are available via `table_borders` (`visible`, `style`, `weight_pt`, `color`, `space`).

#### Creating a New Theme
Create a new theme template with all required fields prefilled:
```bash
python diff_tool.py --create-theme
```

Select the theme in `config.json`:
```json
"theme": ""
```

## Localization
- The default interface and output language is German (`de`).
- To change it, set the `language` value in your `config.json` file to a language code available in the `lang` directory.
- Default languages: `de` (German), `en` (English)
- Additional languages can be added by creating new JSON files in the `lang` directory.
- Each file should be named according to its language code (e.g. `fr.json` for French).
- GitDiff2Docx automatically detects all available languages based on the JSON files present in the `lang` directory.

## Ignoring Files and Directories
You can exclude files or directories from being included in the diff report using a `.gddignore` file located in the target repository.
This file works exactly like a `.gitignore`, supporting the same syntax and matching rules.

## Disclaimer
Use this tool at your own risk. Always verify the generated reports for accuracy.