Not a member of gistpad yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -euo pipefail
- # Check if an ID was provided
- if [ -z "${1:-}" ]; then
- echo "Usage: get_mr_diff <MR_ID> [BASE_REF]"
- echo "Example: get_mr_diff 1234 origin/develop"
- exit 1
- fi
- mr_id="$1"
- base_ref="${2:-origin/develop}" # target branch ref (default)
- output_dir="/Users/arun/Downloads/fulldiff"
- output_file="${output_dir}/MR-${mr_id}.diff"
- mkdir -p "$output_dir"
- # Make sure base ref exists/updated locally
- # If base_ref is origin/<branch>, fetch that branch
- if [[ "$base_ref" == origin/* ]]; then
- base_branch="${base_ref#origin/}"
- git fetch origin "$base_branch" >/dev/null 2>&1 || true
- fi
- # Fetch the specific MR head (Hidden GitLab Ref)
- echo "⬇️ Fetching changes for MR ${mr_id}..."
- git fetch origin "refs/merge-requests/${mr_id}/head" >/dev/null 2>&1
- # Generate the NET diff (final changes only)
- # Triple-dot uses merge-base(base_ref, FETCH_HEAD) -> FETCH_HEAD
- echo "📝 Writing NET diff to file..."
- git diff "$base_ref...FETCH_HEAD" > "$output_file"
- echo "✅ Done! File saved at:"
- echo "$output_file"
RAW Gist Data
Copied
