aboutsummaryrefslogtreecommitdiff
path: root/git-subtree-update
blob: af45ed69ce3de8b212987773e0f20d6985778d4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#
# Update a subtree.
#

# Parameters
BASENAME="`basename $0`"
REMOTE="$1"
FOLDER="$2"

# Syntax
if [ -z "$2" ]; then
  echo "usage: $BASENAME <gitremote> <folder>"
  exit 1
fi

# Check remote
if ! git remote | grep -qe "^$REMOTE"; then
  echo "fatal: no such remote $REMOTE"
  exit
fi

# Fetch the remote
git fetch $REMOTE master

# Process
if [ ! -d "$FOLDER" ]; then
  # Add a subtree
  git subtree add --prefix $FOLDER $REMOTE master --squash
else
  # Update a subtree
  git subtree pull --prefix $FOLDER $REMOTE master --squash
fi