cogito: understand permissions written as "100755"
[cogito.git] / cg-update
blob25d26dae1cd2a0098374e46e5dfdb6ffd402ce43
1 #!/usr/bin/env bash
3 # Fetch and merge changes from a remote repository
4 # Copyright (c) Petr Baudis, 2005
6 # Takes the branch name as an argument, defaulting to 'origin' or the
7 # current branch's default remote branch, see `cg-fetch` for details.
9 # This is similar to running cg-fetch and cg-merge commands successively.
10 # Please refer to the documentation of those commands for more details
11 # about the operation. Note that if you are not doing own development
12 # but only following some project, it is recommended to use this command
13 # instead of `cg-fetch` + `cg-merge` since `cg-update` can handle some
14 # additional corner cases (in particular, if the remote branch rebases,
15 # `cg-update` will fast-forward instead of doing a tree merge and diverging).
17 # Note that in the GIT newspeak, the operation being performed by cg-update
18 # is now called 'pull', even though in the past and in many other version
19 # control systems systems, 'pull' is the name for the operation performed by
20 # `cg-fetch`. Please do not let this confuse you. (Cogito won't call this
21 # 'update' operation 'pull', since about everyone but GIT and BK users uses
22 # it in the 'fetch' meaning.)
24 # OPTIONS
25 # -------
26 # -f:: Force the complete fetch even if the heads are the same.
27 # Force the complete fetch even if the heads are the same.
29 # --squash:: Use "squash" merge to record pending commits as a single merge commit
30 # "Squash" merge - condense all the to-be-merged commits to a single
31 # merge commit. This is not to be used lightly; see the cg-merge
32 # documentation for further details.
34 # -v:: Enable verbosity
35 # Display more verbose output - most notably list all the files
36 # touched by the pulled changes.
38 # ENVIRONMENT
39 # -----------
40 # CGFETCH_FLAGS::
41 # Additional flags to pass cg-fetch (useful e.g. for -v -v).
43 # Testsuite: Largely covered (t9210-update, incomplete coverage; missing:
44 # passing the -f, --squash options and CGFETCH_FLAGS)
46 USAGE="cg-update [-f] [--squash] [-v] [BRANCH_NAME]"
47 _git_requires_root=1
49 . "${COGITO_LIB}"cg-Xlib || exit 1
51 force=
52 squash=
53 verbose=
54 while optparse; do
55 if optparse -f; then
56 force=-f
57 elif optparse --squash; then
58 squash=--squash
59 elif optparse -v; then
60 verbose=-v
61 else
62 optfail
64 done
66 name="${ARGS[0]}"
67 [ "$name" ] || name="$(choose_origin branches "where to update from?")" || exit 1
69 # cg-merge can do better decision about fast-forwarding if it sees this.
70 headid=$(get_ref "refs/heads/$name") && export _cg_orig_head="$headid"
72 if [ -s "$_git/branches/$name" ]; then
73 cg-fetch $CGFETCH_FLAGS $force "$name" || exit 1
74 else
75 echo "Updating from a local branch."
77 echo
78 echo "Applying changes..."
79 cg-merge $squash $verbose "$name"