Test commit
[cogito/jonas.git] / cg-mv
blob40cb9fbc4d27d3820fc614be662cc5fa94c87210
1 #!/usr/bin/env bash
3 # Rename or move files in the repository
4 # Copyright (c) Petr Baudis, 2005
6 # Takes either two filenames and removes a file from the first one to
7 # the second one, or a list of filenames and a dirname and moves all
8 # the files to the directory. The changes will be executed in your working
9 # tree immediately, but recorded to the repository only at the time of the
10 # next commit.
12 # Note that so far, GIT/Cogito does not track file renames/moves per se.
13 # Therefore, doing `cg-mv` is currently the same as doing `cg-rm`, `cg-add`
14 # from the Cogito perspective, and no special information is recorded that
15 # the file moved around. When any rename tracking gets involved currently,
16 # it is purely heuristical method executed at the time of examination.
18 # OPTIONS
19 # -------
20 # -f:: Force overwriting of existing files
21 # Remove the target file if it already exists.
23 # Testsuite: TODO
25 USAGE="cg-mv [-f] FILE... DEST"
27 . "${COGITO_LIB}"cg-Xlib || exit 1
29 force=
30 while optparse; do
31 if optparse -f; then
32 force=-f
33 else
34 optfail
36 done
38 [ -n "${ARGS[*]}" ] || usage
40 # Strip trailing / which is something GIT does not bear well, as well as
41 # some relpath issues. Allegedly fixed in GIT in 90924d55c... (post-1.2.4)
42 ARGS2=()
43 for arg in "${ARGS[@]}"; do
44 ARGS2[${#ARGS2[@]}]="$_git_relpath${arg%/}"
45 done
47 git-mv $force "${ARGS2[@]}"