2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
4 * Copyright (C) 2002-2004 David Roundy
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "CommandLineParser.h"
23 #include "GitRunner.h"
29 static const CommandLineOption options
[] = {
31 //{"--boring", "don't skip boring files"},
32 //{"--umask <UMASK>", "specify umask to use when writing."},
37 : AbstractCommand("add")
39 CommandLineParser::addOptionDefinitions(options
);
40 CommandLineParser::setArgumentDefinition("add <FILE or DIRECTORY>" );
43 AbstractCommand::ReturnCodes
Add::run()
45 if (! checkInRepository())
48 foreach(QString arg
, rebasedArguments()) {
51 if (path
.isFile() || path
.isDir()) {
53 QStringList arguments
;
54 arguments
<< "ls-files" << path
.filePath();
55 GitRunner
runner(checker
, arguments
);
56 ReturnCodes rc
= runner
.start(GitRunner::WaitForStandardOutput
);
59 bool shouldAdd
= true;
62 qint64 lineLength
= Vng::readLine(&checker
, buf
, sizeof(buf
));
65 shouldAdd
= false; // lets assume here that the script just doesn't print anything if its not added yet.
69 Logger::info() << "Not adding file, already in the repository: `" << path
.filePath() << "'\n";
70 checker
.waitForFinished();
73 Logger::warn() << "Adding '" << path
.filePath() << "'" << endl
;
76 arguments
<< "update-index" << "--add" << path
.filePath();
77 GitRunner
runner2(git
, arguments
);
78 rc
= runner2
.start(GitRunner::WaitUntilFinished
);
82 else if (path
.isSymLink())
83 Logger::info() << "Ignoring symbolic link '" << path
.filePath() << "'" << endl
;
85 Logger::info() << "Ignoring non-file object '" << path
.filePath() << "'" << endl
;
88 Logger::error() << "Can not add non existing' " << path
.filePath() << "'" << endl
;
93 QString
Add::argumentDescription() const
95 return "<FILE or DIRECTORY>";
98 QString
Add::commandDescription() const
100 return "Add needs to be called whenever you add a new file or directory to your\n"
101 "project. Of course, it also needs to be called when you first create the\n"
102 "project, to let vng know which files should be kept track of.\n";